做地方网站需要什么部门批准哪些网站权重高
- 作者: 多梦笔记
- 时间: 2026年02月16日 16:05
当前位置: 首页 > news >正文
做地方网站需要什么部门批准,哪些网站权重高,重庆市价格信息网官网,page文件怎么转换wordpressSpring Data JPA系列 1、SpringBoot集成JPA及基本使用 2、Spring Data JPA Criteria查询、部分字段查询 3、Spring Data JPA数据批量插入、批量更新真的用对了吗 4、Spring Data JPA的一对一、LazyInitializationException异常、一对多、多对多操作 5、Spring Data JPA自定… Spring Data JPA系列 1、SpringBoot集成JPA及基本使用 2、Spring Data JPA Criteria查询、部分字段查询 3、Spring Data JPA数据批量插入、批量更新真的用对了吗 4、Spring Data JPA的一对一、LazyInitializationException异常、一对多、多对多操作 5、Spring Data JPA自定义Id生成策略、复合主键配置、Auditing使用 6、【源码】Spring Data JPA原理解析之Repository的自动注入一 7、【源码】Spring Data JPA原理解析之Repository的自动注入二 8、【源码】Spring Data JPA原理解析之Repository执行过程及SimpleJpaRepository源码 9、【源码】Spring Data JPA原理解析之Repository自定义方法命名规则执行原理一 10、【源码】Spring Data JPA原理解析之Repository自定义方法命名规则执行原理二 11、【源码】Spring Data JPA原理解析之Repository自定义方法添加Query注解的执行原理 前言 上一篇限于篇幅只分享了Repository自定义方法命名规则的方法在QueryExecutorMethodInterceptor的构造方法中通过查询查找策略CreateIfNotFoundQueryLookupStrategy创建一个PartTreeJpaQuery对象。该对象解析方法名称的关键字、查询属性、查询关键字封装成PartTree。而后将Method和PartTreeJpaQuery组合存放在QueryExecutorMethodInterceptor的MapMethod, RepositoryQuery queries中。 本篇继续往下分享Repository自定义方法命名规则的方法是如何调用执行的。 方法调用拦截 【源码】Spring Data JPA原理解析之Repository的自动注入二-CSDN博客 上面博文分享了Repository bean的创建。Respository的bean是一个通过ProxyFactory创建的动态代理对象该代理对象添加了QueryExecutorMethodInterceptor拦截器。 【源码】Spring Data JPA原理解析之Repository执行过程及SimpleJpaRepository源码-CSDN博客 博客中介绍了动态代理拦截当Repository中的接口被调用的时候会执行ReflectiveMethodInvocation.proceed()的方法在该方法中循环遍历所有的拦截器执行拦截器的invoke(MethodInvocation invocation)方法。 所以会执行QueryExecutorMethodInterceptor.invoke()方法。QueryExecutorMethodInterceptor的相关代码如下 package org.springframework.data.repository.core.support;/*** 此MethodInterceptor拦截对自定义实现的方法的调用当自定义的方法被调用时会被该类拦截。* 此外它还解析对finder的方法调用并触发它们的执行。如果返回true则可以依赖于设置自定义存储库实现实例。/ class QueryExecutorMethodInterceptor implements MethodInterceptor {// Repository信息为DefaultRepositoryInformation对象。获取Repository信息getRepositoryInformation()返回一个RepositoryInformation对象。// 如子类JpaRepositoryFactory指定baseClass为SimpleJpaRepository.classprivate final RepositoryInformation repositoryInformation;// 方法缓存key为方法value为对应方法的查询解析信息private final MapMethod, RepositoryQuery queries;// 方法调用缓存key为方法value为对应方法调用时要执行的执行器private final MapMethod, RepositoryMethodInvoker invocationMetadataCache new ConcurrentReferenceHashMap();// 查询执行结果处理器private final QueryExecutionResultHandler resultHandler;// 在实体类中添加NamedQueries注解配置相关查询信息默认为空private final NamedQueries namedQueries;private final ListQueryCreationListener? queryPostProcessors;private final RepositoryInvocationMulticaster invocationMulticaster;// 省略其他OverrideNullablepublic Object invoke(SuppressWarnings(null) MethodInvocation invocation) throws Throwable {Method method invocation.getMethod();// 通过返回的返回值获取执行适配器默认都为nullQueryExecutionConverters.ExecutionAdapter executionAdapter QueryExecutionConverters //.getExecutionAdapter(method.getReturnType());if (executionAdapter null) {return resultHandler.postProcessInvocationResult(doInvoke(invocation), method);}return executionAdapter //.apply(() - resultHandler.postProcessInvocationResult(doInvoke(invocation), method));}Nullableprivate Object doInvoke(MethodInvocation invocation) throws Throwable {Method method invocation.getMethod();// 判断方法是否存在RepositoryQuery。在构造函数中会解析Repository中的查询方法并缓存到Mapif (hasQueryFor(method)) {RepositoryMethodInvoker invocationMetadata invocationMetadataCache.get(method);if (invocationMetadata null) {// 首次执行对应方法先创建一个RepositoryQueryMethodInvoker对象保存方法即方法对应的RepositoryQueryinvocationMetadata RepositoryMethodInvoker.forRepositoryQuery(method, queries.get(method));// 加入缓存invocationMetadataCache.put(method, invocationMetadata);}// 获取方法所在的Repository类名、方法的参数值【invocation.getArguments()】执行RepositoryQueryMethodInvoker.invoke()方法return invocationMetadata.invoke(repositoryInformation.getRepositoryInterface(), invocationMulticaster,invocation.getArguments());}// 如果能够处理该查询方法则不执行invocation.proceed()即结束拦截器链return invocation.proceed();}/** 判断是否为给定方法执行查询/private boolean hasQueryFor(Method method) {return queries.containsKey(method);}} 1.1 在QueryExecutorMethodInterceptor.invoke()中核心功能如下 1执行doInvoke()方法执行数据库相关操作获取返回信息 2执行resultHandler.postProcessInvocationResult()进行返回值类型转换 1.2 在doInvoke()方法中执行如下 1调用hasQueryFor()方法判断当前方法是否有对应的RepositoryQuery对象。在上一篇博文中以及做了详细介绍该对象是在QueryExecutorMethodInterceptor的构造方法中解析方法信息后封装的和查询相关的信息对象 2如果存在RepositoryQuery对象则执行RepositoryMethodInvoker.forRepositoryQuery(method, queries.get(method))创建一个RepositoryQueryMethodInvoker对象然后执行RepositoryQueryMethodInvoker.invoke()方法 3如果不存在RepositoryQuery对象则执行invocation.proceed()执行ReflectiveMethodInvocation.proceed()方法继续执行下一个拦截器或执行target的对应方法 RepositoryQueryMethodInvoker RepositoryQueryMethodInvoker查询方法回调类的核心代码如下 abstract class RepositoryMethodInvoker {private final Method method;private final Class? returnedType;private final Invokable invokable;private final boolean suspendedDeclaredMethod;SuppressWarnings(ReactiveStreamsUnusedPublisher)protected RepositoryMethodInvoker(Method method, Invokable invokable) {this.method method;if (KotlinDetector.isKotlinReflectPresent()) {// 省略其他} else {this.suspendedDeclaredMethod false;this.returnedType method.getReturnType();this.invokable invokable;}}static RepositoryQueryMethodInvoker forRepositoryQuery(Method declaredMethod, RepositoryQuery query) {return new RepositoryQueryMethodInvoker(declaredMethod, query);}Nullablepublic Object invoke(Class? repositoryInterface, RepositoryInvocationMulticaster multicaster, Object[] args)throws Exception {return doInvoke(repositoryInterface, multicaster, args);}Nullableprivate Object doInvoke(Class? repositoryInterface, RepositoryInvocationMulticaster multicaster, Object[] args)throws Exception {// 创建一个RepositoryMethodInvocationCaptor对象RepositoryMethodInvocationCaptor invocationResultCaptor RepositoryMethodInvocationCaptor.captureInvocationOn(repositoryInterface);try {// 执行对应方法的RepositoryQuery的execute方法Object result invokable.invoke(args);if (result ! null ReactiveWrappers.supports(result.getClass())) {return new ReactiveInvocationListenerDecorator().decorate(repositoryInterface, multicaster, args, result);}if (result instanceof Stream) {return ((Stream?) result).onClose(() - multicaster.notifyListeners(method, args, computeInvocationResult(invocationResultCaptor.success())));}// 执行结果通知。回调RepositoryMethodInvocationListener.afterInvocation()multicaster.notifyListeners(method, args, computeInvocationResult(invocationResultCaptor.success()));return result;} catch (Exception e) {multicaster.notifyListeners(method, args, computeInvocationResult(invocationResultCaptor.error(e)));throw e;}}private RepositoryMethodInvocation computeInvocationResult(RepositoryMethodInvocationCaptor captured) {return new RepositoryMethodInvocation(captured.getRepositoryInterface(), method, captured.getCapturedResult(),captured.getDuration());}interface Invokable {NullableObject invoke(Object[] args) throws Exception;}private static class RepositoryQueryMethodInvoker extends RepositoryMethodInvoker {public RepositoryQueryMethodInvoker(Method method, RepositoryQuery repositoryQuery) {// repositoryQuery::execute方法回调声明作为参数赋值给invokable当执行invokable.invoke()时// 执行repositoryQuery.execute()方法super(method, repositoryQuery::execute);}}// 省略其他 } RepositoryQueryMethodInvoker是私有静态内部类父类为RepositoryMethodInvoker。 在上面讲解的1.2的2中通过RepositoryMethodInvoker.forRepositoryQuery(method, queries.get(method))创建一个RepositoryQueryMethodInvoker对象将repositoryQuery::execute方法回调声明作为参数赋值给invokable。 当执行RepositoryQueryMethodInvoker.invoke()时执行doInvoke()方法该方法执行如下 1创建一个RepositoryMethodInvocationCaptor对象 2执行invokable.invoke()即执行对应方法的RepositoryQuery的execute方法执行数据库操作 RepositoryQuery.execute() - AbstractJpaQuery.execute() - AbstractJpaQuery.doExecute() - JpaQueryExecution.execute() - JpaQueryExecution.doExecute()。 3执行结果通知。回调RepositoryMethodInvocationListener.afterInvocation() 4返回2中的返回值 第2中调用的JpaQueryExecution.doExecute()是一个抽象方法实现类如下 针对数据库表操作后不同的返回值信息使用不同的实现类且实现类都是JpaQueryExecution的内部类。以下以SingleEntityExecution为例。 public abstract class JpaQueryExecution {static class SingleEntityExecution extends JpaQueryExecution {Overrideprotected Object doExecute(AbstractJpaQuery query, JpaParametersParameterAccessor accessor) {return query.createQuery(accessor).getSingleResult();}} } 执行AbstractJpaQuery.createQuery()获取一个Query对象最后调用Query.getSingleResult()返回一个查询执行结果。其他的实现类处理类似只是最后调用Query的不同方法从数据库中查询不同的结果值。 AbstractJpaQuery AbstractJpaQuery的相关代码如下 /** 记录Repository中每个方法解析后的信息/ public abstract class AbstractJpaQuery implements RepositoryQuery {private final JpaQueryMethod method;private final EntityManager em;private final JpaMetamodel metamodel;// 根据EntityManager返回PersistenceProvider。PersistenceProvider是枚举类型有HIBERNATE、ECLIPSELINK、GENERIC_JPA。// 不同的PersistenceProviderextractQueryString、getIdentifierFrom等方式不一样private final PersistenceProvider provider;// 根据查询方法的返回值使用不同的执行器private final LazyJpaQueryExecution execution;// 参数绑定器final LazyParameterBinder parameterBinder Lazy.of(this::createBinder);NullableOverridepublic Object execute(Object[] parameters) {return doExecute(getExecution(), parameters);}/** 执行查询* param execution 执行器。主要根据方法的返回值确定的执行器* param values 方法执行时的参数值* return/Nullableprivate Object doExecute(JpaQueryExecution execution, Object[] values) {// 创建一个JpaParametersParameterAccessor对象保存方法的参数信息及本次查询的参数值JpaParametersParameterAccessor accessor obtainParameterAccessor(values);// 执行数据库查询获取返回值Object result execution.execute(this, accessor);ResultProcessor withDynamicProjection method.getResultProcessor().withDynamicProjection(accessor);return withDynamicProjection.processResult(result, new TupleConverter(withDynamicProjection.getReturnedType()));}private JpaParametersParameterAccessor obtainParameterAccessor(Object[] values) {if (method.isNativeQuery() PersistenceProvider.HIBERNATE.equals(provider)) {return new HibernateJpaParametersParameterAccessor(method.getParameters(), values, em);}return new JpaParametersParameterAccessor(method.getParameters(), values);}/** 获取方法对应的查询执行器/protected JpaQueryExecution getExecution() {// 获取根据返回值确定的查询的执行器JpaQueryExecution execution this.execution.getNullable();if (execution ! null) {return execution;}// 如果添加了Modify注解则返回if (method.isModifyingQuery()) {return new ModifyingExecution(method, em);}// 否则返回单个实体类的执行器return new SingleEntityExecution();}/** 为query添加定义的查询hint信息。方法中添加QueryHints注解/protected T extends Query T applyHints(T query, JpaQueryMethod method) {ListQueryHint hints method.getHints();if (!hints.isEmpty()) {for (QueryHint hint : hints) {applyQueryHint(query, hint);}}// Apply any meta-attributes that existif (method.hasQueryMetaAttributes()) {if (provider.getCommentHintKey() ! null) {query.setHint( //provider.getCommentHintKey(), provider.getCommentHintValue(method.getQueryMetaAttributes().getComment()));}}return query;}protected T extends Query void applyQueryHint(T query, QueryHint hint) {Assert.notNull(query, Query must not be null);Assert.notNull(hint, QueryHint must not be null);query.setHint(hint.name(), hint.value());}/** 为query应用锁模式/private Query applyLockMode(Query query, JpaQueryMethod method) {LockModeType lockModeType method.getLockModeType();return lockModeType null ? query : query.setLockMode(lockModeType);}protected Query createQuery(JpaParametersParameterAccessor parameters) {return applyLockMode(applyEntityGraphConfiguration(applyHints(doCreateQuery(parameters), method), method), method);}/** 如果方法添加EntityGraph注解在query中添加对应的Hint* param query* param method* return/private Query applyEntityGraphConfiguration(Query query, JpaQueryMethod method) {JpaEntityGraph entityGraph method.getEntityGraph();if (entityGraph ! null) {QueryHints hints Jpa21Utils.getFetchGraphHint(em, method.getEntityGraph(),getQueryMethod().getEntityInformation().getJavaType());hints.forEach(query::setHint);}return query;}/** 为查询创建一个Query并调用query.setParameter()设置参数值及分页信息/protected abstract Query doCreateQuery(JpaParametersParameterAccessor accessor);// 省略其他 } 在createQuery()方法中执行如下 1调用抽象方法doCreateQuery()获取一个Query 对于自定义方法命名规则的方法实现在PartTreeJpaQuery类。 2执行applyHints()在query中添加对应的Hint 3执行applyEntityGraphConfiguration()如果方法添加EntityGraph注解在query中添加对应的Hint 4执行applyLockMode()为query应用锁模式 PartTreeJpaQuery PartTreeJpaQuery的相关代码如下 package org.springframework.data.jpa.repository.query;/** 保存了方法信息包括方法、方法参数、方法名称解析后的Part树、对应的查询query、查询计数countQuery等信息/ public class PartTreeJpaQuery extends AbstractJpaQuery {private final PartTree tree;private final JpaParameters parameters;private final QueryPreparer query;private final QueryPreparer countQuery;private final EntityManager em;private final EscapeCharacter escape;private final JpaMetamodelEntityInformation?, Object entityInformation;/** 为查询创建一个Query并调用query.setParameter()设置参数值及分页信息/Overridepublic Query doCreateQuery(JpaParametersParameterAccessor accessor) {return query.createQuery(accessor);}OverrideSuppressWarnings(unchecked)public TypedQueryLong doCreateCountQuery(JpaParametersParameterAccessor accessor) {return (TypedQueryLong) countQuery.createQuery(accessor);}private class QueryPreparer {// 缓存创建的对象private final Nullable CriteriaQuery? cachedCriteriaQuery;private final Nullable ParameterBinder cachedParameterBinder;private final QueryParameterSetter.QueryMetadataCache metadataCache new QueryParameterSetter.QueryMetadataCache();QueryPreparer(boolean recreateQueries) {JpaQueryCreator creator createCreator(null);if (recreateQueries) {this.cachedCriteriaQuery null;this.cachedParameterBinder null;} else {// 子类CountQueryPreparer的createQuery()执行JpaCountQueryCreator重写的complete()方法// 执行query.select()select为builder.count()并加上predicate条件信息this.cachedCriteriaQuery creator.createQuery();this.cachedParameterBinder getBinder(creator.getParameterExpressions());}}/** 为查询创建一个Query并调用query.setParameter()设置参数值及分页信息/public Query createQuery(JpaParametersParameterAccessor accessor) {CriteriaQuery? criteriaQuery cachedCriteriaQuery;ParameterBinder parameterBinder cachedParameterBinder;if (cachedCriteriaQuery null || accessor.hasBindableNullValue()) {JpaQueryCreator creator createCreator(accessor);criteriaQuery creator.createQuery(getDynamicSort(accessor));ListParameterMetadata? expressions creator.getParameterExpressions();parameterBinder getBinder(expressions);}if (parameterBinder null) {throw new IllegalStateException(ParameterBinder is null);}// 通过EntityManager.createQuery(criteriaQuery)返回TypedQueryTypedQuery? query createQuery(criteriaQuery);ScrollPosition scrollPosition accessor.getParameters().hasScrollPositionParameter()? accessor.getScrollPosition(): null;// 调用invokeBinding()执行query.setParameter()方法设置查询的条件参数值如果有分页设置分页信息// 如果有需要设置返回最大值信息return restrictMaxResultsIfNecessary(invokeBinding(parameterBinder, query, accessor, this.metadataCache),scrollPosition);}SuppressWarnings(ConstantConditions)private Query restrictMaxResultsIfNecessary(Query query, Nullable ScrollPosition scrollPosition) {if (scrollPosition instanceof OffsetScrollPosition offset !offset.isInitial()) {query.setFirstResult(Math.toIntExact(offset.getOffset()) 1);}if (tree.isLimiting()) {if (query.getMaxResults() ! Integer.MAX_VALUE) {if (query.getMaxResults() tree.getMaxResults() query.getFirstResult() 0) {query.setFirstResult(query.getFirstResult() - (query.getMaxResults() - tree.getMaxResults()));}}query.setMaxResults(tree.getMaxResults());}if (tree.isExistsProjection()) {query.setMaxResults(1);}return query;}/** 通过EntityManager.createQuery(criteriaQuery)返回TypedQuery/private TypedQuery? createQuery(CriteriaQuery? criteriaQuery) {if (this.cachedCriteriaQuery ! null) {synchronized (this.cachedCriteriaQuery) {return getEntityManager().createQuery(criteriaQuery);}}return getEntityManager().createQuery(criteriaQuery);}protected JpaQueryCreator createCreator(Nullable JpaParametersParameterAccessor accessor) {EntityManager entityManager getEntityManager();CriteriaBuilder builder entityManager.getCriteriaBuilder();ResultProcessor processor getQueryMethod().getResultProcessor();ParameterMetadataProvider provider;ReturnedType returnedType;if (accessor ! null) {provider new ParameterMetadataProvider(builder, accessor, escape);returnedType processor.withDynamicProjection(accessor).getReturnedType();} else {provider new ParameterMetadataProvider(builder, parameters, escape);returnedType processor.getReturnedType();}if (accessor ! null accessor.getScrollPosition() instanceof KeysetScrollPosition keyset) {return new JpaKeysetScrollQueryCreator(tree, returnedType, builder, provider, entityInformation, keyset);}return new JpaQueryCreator(tree, returnedType, builder, provider);}/** 调用query.setParameter()方法设置查询的条件参数值如果有分页设置分页信息/protected Query invokeBinding(ParameterBinder binder, TypedQuery? query, JpaParametersParameterAccessor accessor,QueryParameterSetter.QueryMetadataCache metadataCache) {// 将query查询添加到缓存QueryParameterSetter.QueryMetadata metadata metadataCache.getMetadata(query, query);return binder.bindAndPrepare(query, metadata, accessor);}private ParameterBinder getBinder(ListParameterMetadata? expressions) {return ParameterBinderFactory.createCriteriaBinder(parameters, expressions);}private Sort getDynamicSort(JpaParametersParameterAccessor accessor) {return parameters.potentiallySortsDynamically() //? accessor.getSort() //: Sort.unsorted();}}private class CountQueryPreparer extends QueryPreparer {CountQueryPreparer(boolean recreateQueries) {super(recreateQueries);}/** 创建一个JpaCountQueryCreator/Overrideprotected JpaQueryCreator createCreator(Nullable JpaParametersParameterAccessor accessor) {EntityManager entityManager getEntityManager();CriteriaBuilder builder entityManager.getCriteriaBuilder();ParameterMetadataProvider provider;if (accessor ! null) {provider new ParameterMetadataProvider(builder, accessor, escape);} else {provider new ParameterMetadataProvider(builder, parameters, escape);}return new JpaCountQueryCreator(tree, getQueryMethod().getResultProcessor().getReturnedType(), builder, provider);}Overrideprotected Query invokeBinding(ParameterBinder binder, TypedQuery? query, JpaParametersParameterAccessor accessor,QueryParameterSetter.QueryMetadataCache metadataCache) {QueryParameterSetter.QueryMetadata metadata metadataCache.getMetadata(countquery, query);return binder.bind(query, metadata, accessor);}} } 1在PartTreeJpaQuery.doCreateQuery()方法执行QueryPreparer.createQuery()方法。 2QueryPreparer.createQuery()方法先调用createQuery()执行如下 2.1通过EntityManager.createQuery(criteriaQuery)返回TypedQuery 2.2执行invokeBinding()在TypedQuery对象中调用query.setParameter()绑定查询条件的参数值如果有分页设置分页信息 通过执行ParameterBinder.bindAndPrepare()方法调用query.setParameter()绑定查询条件的参数值如果有分页设置分页信息。 2.3执行restrictMaxResultsIfNecessary()如果有需要设置返回最大值信息 ParameterBinder ParameterBinder的代码如下 package org.springframework.data.jpa.repository.query;/** ParameterBinder用于将方法参数绑定到Query。通常在执行AbstractJpaQuery时执行。*/ public class ParameterBinder {static final String PARAMETER_NEEDS_TO_BE_NAMED For queries with named parameters you need to provide names for method parameters; Use Param for query method parameters, or when on Java 8 use the javac flag -parameters;private final JpaParameters parameters;// 查询方法对应的参数设置器private final IterableQueryParameterSetter parameterSetters;private final boolean useJpaForPaging;ParameterBinder(JpaParameters parameters, IterableQueryParameterSetter parameterSetters) {this(parameters, parameterSetters, true);}public ParameterBinder(JpaParameters parameters, IterableQueryParameterSetter parameterSetters,boolean useJpaForPaging) {Assert.notNull(parameters, JpaParameters must not be null);Assert.notNull(parameterSetters, Parameter setters must not be null);this.parameters parameters;this.parameterSetters parameterSetters;this.useJpaForPaging useJpaForPaging;}public T extends Query T bind(T jpaQuery, QueryParameterSetter.QueryMetadata metadata,JpaParametersParameterAccessor accessor) {// 绑定参数值bind(metadata.withQuery(jpaQuery), accessor, ErrorHandling.STRICT);return jpaQuery;}public void bind(QueryParameterSetter.BindableQuery query, JpaParametersParameterAccessor accessor,ErrorHandling errorHandling) {// 遍历方法的参数设置器调用QueryParameterSetter.setParameter() - query.setParameter()为查询语句赋值for (QueryParameterSetter setter : parameterSetters) {setter.setParameter(query, accessor, errorHandling);}}Query bindAndPrepare(Query query, QueryParameterSetter.QueryMetadata metadata,JpaParametersParameterAccessor accessor) {// 绑定参数。调用query.setParameter()为查询赋值bind(query, metadata, accessor);// 如果没有分页直接返回if (!useJpaForPaging || !parameters.hasLimitingParameters() || accessor.getPageable().isUnpaged()) {return query;}// 设置分页信息query.setFirstResult(PageableUtils.getOffsetAsInteger(accessor.getPageable()));query.setMaxResults(accessor.getPageable().getPageSize());return query;} } 小结 限于篇幅本篇先分享到这里。结合上一篇【源码】Spring Data JPA原理解析之Repository自定义方法命名规则执行原理一一起做一个小结 1Repository的代理类中会添加QueryExecutorMethodInterceptor方法拦截器 2QueryExecutorMethodInterceptor方法拦截器的构造方法中会根据查询查找策略CreateIfNotFoundQueryLookupStrategy获得RepositoryQuery对象解析方法。对于按方法命名规则实现的方法使用的RepositoryQuery对象为PartTreeJpaQuery 3在PartTreeJpaQuery构造方法中创建一个PartTree对象解析方法名称中的起始关键字【如findBy、readBy、deleteBy等】、条件属性【实体类中的属性】、查询关键字【Between、In、Equals等】 4创建对应方法的countQuery和query将解析出的查询的基础信息封装在QueryPreparer对象中根据解析出的查询信息创建CriteriaQuery对象 5解析完方法信息保存在PartTreeJpaQuery后保存到QueryExecutorMethodInterceptor的MapMethod, RepositoryQuery queries中 6当Repository的接口被调用的时候在ReflectiveMethodInvocation.proceed()中先执行QueryExecutorMethodInterceptor.invoke()方法 6.1调用doInvoke()方法获取数据库执行后的数据 6.1.1调用RepositoryQueryMethodInvoker.invoke() - RepositoryQuery.execute() - AbstractJpaQuery.execute() - AbstractJpaQuery.doExecute() - JpaQueryExecution.execute() - JpaQueryExecution.doExecute() 6.1.2doExecute()是一个抽象方法针对不同的数据库查询返回值信息使用不同的实现类。所有的实现类都会先调用AbstractJpaQuery.createQuery()获取一个Query对象 6.1.3在AbstractJpaQuery.createQuery()中调用抽象方法doCreateQuery()。对于按方法命名规则的Repository接口实现类为PartTreeJpaQuery 6.1.4在PartTreeJpaQuery.coCreateQuery()方法中通过EntityManager.createQuery(criteriaQuery)返回TypedQuery然后执行invokeBinding()在TypedQuery对象中调用query.setParameter()绑定查询条件的参数值如果有分页设置分页信息 6.1.5参数完参数在6.1.3中设置hint等。然后执行6.1.2中的具体实现类执行数据库查询。如SingleEntityExecution实现类执行TypeQuery.getSingleResult()然后单个结果 6.2调用resultHandler.postProcessInvocationResult()对数据库查询后的值进行返回值类型转换 关于本篇内容你有什么自己的想法或独到见解欢迎在评论区一起交流探讨下吧。
- 上一篇: 做导购网站 商品百度提交收录入口
- 下一篇: 做地区招聘网站公司发展规划怎么写
相关文章
-
做导购网站 商品百度提交收录入口
做导购网站 商品百度提交收录入口
- 站长
- 2026年02月16日
-
做弹幕网站有哪些织梦cms仿某作文网站整站源码(带采集)安装数据库
做弹幕网站有哪些织梦cms仿某作文网站整站源码(带采集)安装数据库
- 站长
- 2026年02月16日
-
做单页网站要多少钱地下城做心悦任务的网站
做单页网站要多少钱地下城做心悦任务的网站
- 站长
- 2026年02月16日
-
做地区招聘网站公司发展规划怎么写
做地区招聘网站公司发展规划怎么写
- 站长
- 2026年02月16日
-
做地区招聘网站深圳企业集团网站建设
做地区招聘网站深圳企业集团网站建设
- 站长
- 2026年02月16日
-
做的比较好的冷柜网站有哪些洛阳市霞光游乐设备有限公司
做的比较好的冷柜网站有哪些洛阳市霞光游乐设备有限公司
- 站长
- 2026年02月16日
