From 5f653cd83425db29ccf514e9fd966a90c7eeab32 Mon Sep 17 00:00:00 2001 From: dongyukun <1208714201@qq.com> Date: 星期四, 02 一月 2025 13:47:45 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/config/MyBatisConfiguration.java | 152 +++++++++++++++++++++++++++----------------------- 1 files changed, 82 insertions(+), 70 deletions(-) diff --git a/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/config/MyBatisConfiguration.java b/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/config/MyBatisConfiguration.java index 5a00cb6..e841574 100644 --- a/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/config/MyBatisConfiguration.java +++ b/iailab-framework/iailab-common-mybatis/src/main/java/com/iailab/framework/mybatis/config/MyBatisConfiguration.java @@ -1,72 +1,84 @@ -package com.iailab.framework.mybatis.config; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.iailab.framework.mybatis.core.handler.MybatisHandler; -import org.apache.ibatis.session.SqlSessionFactory; -import org.apache.ibatis.type.JdbcType; -import org.mybatis.spring.SqlSessionFactoryBean; -import org.mybatis.spring.SqlSessionTemplate; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; - - -/** - * @author houzhongjian - * @Title: MyBatisConfiguration - * @ProjectName design-parent - * @Description: 解决独立启动某个服务时报错问题 No typehandler found for property sqlSessionTemplate - * @date 2024/7/2 16:35 - */ -@Configuration -public class MyBatisConfiguration { - - // 配置mapper的扫描,找到所有的mapper.xml映射文件 - @Value("${iailab.info.base-package}") - private String mapperLocations; - - -// @Bean(name = "dataSource") -// @ConfigurationProperties(prefix = "spring.datasource.test1") +//package com.iailab.framework.mybatis.config; +// +//import com.alibaba.fastjson.JSONArray; +//import com.alibaba.fastjson.JSONObject; +//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +//import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; +//import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; +//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +//import com.iailab.framework.mybatis.core.handler.MybatisHandler; +//import com.iailab.framework.mybatis.interceptor.DataFilterInterceptor; +//import org.apache.ibatis.session.SqlSessionFactory; +//import org.apache.ibatis.type.JdbcType; +//import org.mybatis.spring.SqlSessionFactoryBean; +//import org.mybatis.spring.SqlSessionTemplate; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.boot.jdbc.DataSourceBuilder; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.context.annotation.Primary; +//import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +//import org.springframework.jdbc.datasource.DataSourceTransactionManager; +// +// +///** +// * @author houzhongjian +// * @Title: MyBatisConfiguration +// * @ProjectName design-parent +// * @Description: 解决独立启动某个服务时报错问题 No typehandler found for property sqlSessionTemplate +// * @date 2024/7/2 16:35 +// */ +//@Configuration +//public class MyBatisConfiguration { +// +// // 配置mapper的扫描,找到所有的mapper.xml映射文件 +//// @Value("${iailab.info.base-package}") +// @Value("${mybatis-plus.mapper-locations}") +// private String mapperLocations; +// +// @Bean // @Primary -// public DataSource dataSource() { -// return DataSourceBuilder.create().build(); +// public SqlSessionFactory sqlSessionFactory() throws Exception { +// SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); +// sqlSessionFactoryBean.setDataSource(DataSourceBuilder.create().build()); +// sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations)); +// sqlSessionFactoryBean.setConfiguration(buildConfiguration()); +// return sqlSessionFactoryBean.getObject(); // } - - @Bean - @Primary - public SqlSessionFactory sqlSessionFactory() throws Exception { - SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); - sqlSessionFactoryBean.setDataSource(DataSourceBuilder.create().build()); - sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations)); - sqlSessionFactoryBean.setConfiguration(buildConfiguration()); - return sqlSessionFactoryBean.getObject(); - } - - @Bean - @Primary - public SqlSessionTemplate sqlSessionTemplate() throws Exception { - return new SqlSessionTemplate(sqlSessionFactory()); - } - - @Bean - @Primary - public DataSourceTransactionManager transactionManager() { - return new DataSourceTransactionManager(DataSourceBuilder.create().build()); - } - - private org.apache.ibatis.session.Configuration buildConfiguration() { - org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(); - configuration.getTypeHandlerRegistry().register(JSONObject.class, JdbcType.VARCHAR, MybatisHandler.class); - configuration.getTypeHandlerRegistry().register(JSONArray.class, JdbcType.VARCHAR, MybatisHandler.class); - return configuration; - } - - -} \ No newline at end of file +// +// @Bean +// @Primary +// public SqlSessionTemplate sqlSessionTemplate() throws Exception { +// return new SqlSessionTemplate(sqlSessionFactory()); +// } +// +// @Bean +// @Primary +// public DataSourceTransactionManager transactionManager() { +// return new DataSourceTransactionManager(DataSourceBuilder.create().build()); +// } +// +// private org.apache.ibatis.session.Configuration buildConfiguration() { +// org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(); +// configuration.getTypeHandlerRegistry().register(JSONObject.class, JdbcType.VARCHAR, MybatisHandler.class); +// configuration.getTypeHandlerRegistry().register(JSONArray.class, JdbcType.VARCHAR, MybatisHandler.class); +// return configuration; +// } +// +// @Bean +// public MybatisPlusInterceptor mybatisPlusInterceptor() { +// MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); +// // 数据权限 +// mybatisPlusInterceptor.addInnerInterceptor(new DataFilterInterceptor()); +// // 分页插件 +// mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor()); +// // 乐观锁 +// mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); +// // 防止全表更新与删除 +// mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor()); +// +// return mybatisPlusInterceptor; +// } +// +// +//} \ No newline at end of file -- Gitblit v1.9.3