本文整理汇总了Java中org.apache.ibatis.annotations.Mapper类的典型用法代码示例。如果您正苦于以下问题:Java Mapper类的具体用法?Java Mapper怎么用?Java Mapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mapper类属于org.apache.ibatis.annotations包,在下文中一共展示了Mapper类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerBeanDefinitions
import org.apache.ibatis.annotations.Mapper; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
logger.debug("Searching for mappers annotated with @Mapper");
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
try {
if (this.resourceLoader != null) {
scanner.setResourceLoader(this.resourceLoader);
}
List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
if (logger.isDebugEnabled()) {
for (String pkg : packages) {
logger.debug("Using auto-configuration base package '" + pkg + "'");
}
}
scanner.setAnnotationClass(Mapper.class);
scanner.registerFilters();
scanner.doScan(StringUtils.toStringArray(packages));
} catch (IllegalStateException ex) {
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled." + ex);
}
}
示例2: registerBeanDefinitions
import org.apache.ibatis.annotations.Mapper; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
logger.debug("Searching for mappers annotated with @Mapper");
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
scanner.setMapperProperties(environment);
try {
if (this.resourceLoader != null) {
scanner.setResourceLoader(this.resourceLoader);
}
List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
if (logger.isDebugEnabled()) {
for (String pkg : packages) {
logger.debug("Using auto-configuration base package '{}'", pkg);
}
}
scanner.setAnnotationClass(Mapper.class);
scanner.registerFilters();
scanner.doScan(StringUtils.toStringArray(packages));
} catch (IllegalStateException ex) {
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
}
}
示例3: createClassPathMapperScanner
import org.apache.ibatis.annotations.Mapper; //导入依赖的package包/类
private void createClassPathMapperScanner(BeanDefinitionRegistry registry, String prefixName) {
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
try {
if (this.resourceLoader != null) {
scanner.setResourceLoader(this.resourceLoader);
}
List<String> packages = AutoConfigurationPackages.get(beanFactory);
packages.forEach(pkg -> log.info("Using auto-configuration base package '{}'", pkg));
scanner.setAnnotationClass(Mapper.class);
scanner.setSqlSessionFactoryBeanName(prefixName + "SessionFactory");
scanner.registerFilters();
scanner.doScan(StringUtils.toStringArray(packages));
} catch (IllegalStateException ex) {
log.info("Could not determine auto-configuration package", ex);
}
}
示例4: registerBeanDefinitions
import org.apache.ibatis.annotations.Mapper; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
logger.debug("Searching for mappers annotated with @Mapper");
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
try {
if (this.resourceLoader != null) {
scanner.setResourceLoader(this.resourceLoader);
}
List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
if (logger.isDebugEnabled()) {
packages.forEach(pkg -> logger.debug("Using auto-configuration base package '{}'", pkg));
}
scanner.setAnnotationClass(Mapper.class);
scanner.registerFilters();
scanner.doScan(StringUtils.toStringArray(packages));
} catch (IllegalStateException ex) {
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
}
}
示例5: addPackageToScan
import org.apache.ibatis.annotations.Mapper; //导入依赖的package包/类
private void addPackageToScan(String pack) {
try {
Enumeration<URL> resources = Thread.currentThread()
.getContextClassLoader()
.getResources(pack.replace(".", "/"));
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
File file = new File(resource.getPath());
for (File f : file.listFiles()) {
//如果还是个包,则继续扫描
if (f.isDirectory()) {
addPackageToScan(pack + "." + f.getName());
}
else {
Class<?> class1 = Class.forName(pack + "." + f.getName().replace(".class", ""));
if (containBeanAnnotation(class1)) {
classList.add(class1);
this.register.registerBean(class1.newInstance());
log.info("register bean {}", class1);
}
if (class1.getAnnotation(Mapper.class) != null) {
MybatisConfig.addMapper(class1);
log.info("add mapper {}", class1);
MybatisConfig.buildSessionFactory();
this.register.registerBean(class1.getName(), MybatisConfig.getMapper(class1));
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: makeClass
import org.apache.ibatis.annotations.Mapper; //导入依赖的package包/类
protected TypeSpec.Builder makeClass(TypeElement clazzElement, RedisMapperProperties properties) {
TypeSpec.Builder clazzBuilder = TypeSpec.interfaceBuilder(clazzElement.getSimpleName().toString() + STAFF)
.addModifiers(Modifier.PUBLIC);
clazzBuilder.addAnnotation(Mapper.class);
if (!checkXMLFileExist(clazzElement)) {
AnnotationSpec cacheAnnotation = AnnotationSpec.builder(CacheNamespace.class)
.addMember("flushInterval", "$L", properties.getFlushInterval())
.addMember("implementation", "$L.class", properties.getImplementation())
.addMember("eviction", "$L.class", properties.getEviction())
.addMember("size", "$L", properties.getSize())
.addMember("readWrite", "$L", properties.isReadWrite())
.addMember("blocking", "$L", properties.isBlocking())
.build();
clazzBuilder.addAnnotation(cacheAnnotation);
for (TypeMirror interfaceClass : clazzElement.getInterfaces()) {
clazzBuilder.addSuperinterface(TypeName.get(interfaceClass));
}
clazzBuilder.addSuperinterface(TypeName.get(clazzElement.asType()));
} else {
updateXML(clazzElement, properties);
}
return clazzBuilder;
}