SpringBoot MyBatis基础配置
来源:互联网 发布:规划算法 pdf 编辑:程序博客网 时间:2024/05/16 19:38
习惯了spring的xml配置,结构清晰明了,springboot改为了java代码配置,这种配置和JFinal有点类似。
/** * MyBatis基础配置 * * @author * @since 2015-12-19 10:11 */@Configuration@EnableTransactionManagementpublic class MyBatisConfig implements TransactionManagementConfigurer { @Autowired DataSource dataSource; @Bean(name = "sqlSessionFactory") public SqlSessionFactory sqlSessionFactoryBean() { //配置框架数据源 ApplicationContextHelper.setDataSource(dataSource); PackagesSqlSessionFactoryBean bean = new PackagesSqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setTypeAliasesPackage("com.sys.module.*.entity"); bean.setTypeAliases(new Class[]{CommonParamEntity.class}); //增加自编写分页插件 MyBatisPageInterceptor page = new MyBatisPageInterceptor(); page.databaseType = "DB2"; page.pageRex = ".*ByPage$"; //添加插件 bean.setPlugins(new Interceptor[]{page}); //此段代码用来解决实体没有被扫描的问题 bean.setVfs(SpringBootVFS.class); //添加XML目录 ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try { bean.setMapperLocations(resolver.getResources("classpath:com/sys/module/*/dao/*.mapper.xml")); return bean.getObject(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } @Bean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { return new SqlSessionTemplate(sqlSessionFactory); } @Bean @Override public PlatformTransactionManager annotationDrivenTransactionManager() { return new DataSourceTransactionManager(dataSource); }}
阅读全文
0 0
- SpringBoot MyBatis基础配置
- springboot mybatis druid配置
- springboot-mybatis 配置详解
- Springboot 配置mybatis
- MyBatis springboot gradle 开发配置
- 【2】SpringBoot的MyBatis配置
- SpringBoot学习(3) 配置MyBatis
- springboot+mybatis手动配置数据源
- SpringBoot系列—基础配置
- springBoot基础系列--properties配置
- springBoot基础系列--properties配置
- springBoot基础系列--properties配置
- SpringBoot多数据源的配置(SpringBoot+MyBatis)
- SpringBoot、MyBatis配置多数据源
- springboot+mybatis配置多数据源
- Springboot项目配置myBatis连接MySQL数据库
- SpringBoot + MyBatis + DRUID + MySQL Maven依赖配置
- Springboot配置Mybatis多数据源
- laravel CURD 查询构造器
- 2017年前端"最受欢迎"调查报告:ES 6,React和Sublime Text依然霸主
- 线程池(ThreadPoolExecutor)处理异步任务
- HDU 4801 Pocket Cube
- 8 访问路径介绍--优化主题系列
- SpringBoot MyBatis基础配置
- postman的使用
- 杭电acm2041:递归楼梯
- 挑战程序竞赛系列(88):3.6平面扫描(2)
- [转-qq_34531925]Webuploader教程(一)——简单实用上传功能
- tensorflow: 打印内存中的变量
- Java实现BASE64Decoder编写加密和解码
- iPhone8 和 X 买哪个?听我的
- 程序员 挣钱比健康重要