通用mapper和mybatis-spring的关系以及与之相似的spring-data-jpa

阅读更多

 

通用mapper和mybatis-spring的关系以及与之相似的spring-data-jpa

 

 

 

整合东西到框架里面去就是集成框架的接口类之后进行复写:

 

 

public class MapperScannerConfigurer

  extends org.mybatis.spring.mapper.MapperScannerConfigurer

 

 

 

 

 

 

从这里看出spring-mybatis本生就具备把mapper生成代理实现类,那么通用mapper就是做了单表的操作的省略,

生成是mybatis-generator

 

spring-data-jpa:

 

生成代码+成代理+单表操作省略

 

ClassPathBeanDefinitionScanner:

 

private BeanNameGenerator beanNameGenerator = new AnnotationBeanNameGenerator();///在打断点的时候不知用的到底是接口的那个实现类看前面注入的地方

 

protected Set doScan(String... basePackages) {

Assert.notEmpty(basePackages, "At least one base package must be specified");

Set beanDefinitions = new LinkedHashSet();

for (String basePackage : basePackages) {///////////////////包可以有多个

Set candidates = findCandidateComponents(basePackage);////////////////////////////////获取一个一个mapper

for (BeanDefinition candidate : candidates) {

ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate);

candidate.setScope(scopeMetadata.getScopeName());

String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry);///在打断点的时候不知用的到底是接口的那个实现类看前面注入的地方

if (candidate instanceof AbstractBeanDefinition) {

postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName);

}

if (candidate instanceof AnnotatedBeanDefinition) {

AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);

}

if (checkCandidate(beanName, candidate)) {

BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName);

definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);

beanDefinitions.add(definitionHolder);//////////////所有的mapper都加到这个集合

registerBeanDefinition(definitionHolder, this.registry);

}

}

}

return beanDefinitions;

}

 

 

 

 

 

你可能感兴趣的:(mapper,mybatis-spring,spring-data-jpa)