提交 | 用户 | 时间
|
d9f9ba
|
1 |
//package com.iailab.framework.mybatis.config; |
H |
2 |
// |
|
3 |
//import com.alibaba.fastjson.JSONArray; |
|
4 |
//import com.alibaba.fastjson.JSONObject; |
|
5 |
//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
|
6 |
//import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; |
|
7 |
//import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; |
|
8 |
//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
|
9 |
//import com.iailab.framework.mybatis.core.handler.MybatisHandler; |
|
10 |
//import com.iailab.framework.mybatis.interceptor.DataFilterInterceptor; |
|
11 |
//import org.apache.ibatis.session.SqlSessionFactory; |
|
12 |
//import org.apache.ibatis.type.JdbcType; |
|
13 |
//import org.mybatis.spring.SqlSessionFactoryBean; |
|
14 |
//import org.mybatis.spring.SqlSessionTemplate; |
|
15 |
//import org.springframework.beans.factory.annotation.Value; |
|
16 |
//import org.springframework.boot.jdbc.DataSourceBuilder; |
|
17 |
//import org.springframework.context.annotation.Bean; |
|
18 |
//import org.springframework.context.annotation.Configuration; |
|
19 |
//import org.springframework.context.annotation.Primary; |
|
20 |
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
|
21 |
//import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
|
22 |
// |
|
23 |
// |
|
24 |
///** |
|
25 |
// * @author houzhongjian |
|
26 |
// * @Title: MyBatisConfiguration |
|
27 |
// * @ProjectName design-parent |
|
28 |
// * @Description: 解决独立启动某个服务时报错问题 No typehandler found for property sqlSessionTemplate |
|
29 |
// * @date 2024/7/2 16:35 |
|
30 |
// */ |
|
31 |
//@Configuration |
|
32 |
//public class MyBatisConfiguration { |
|
33 |
// |
|
34 |
// // 配置mapper的扫描,找到所有的mapper.xml映射文件 |
|
35 |
//// @Value("${iailab.info.base-package}") |
|
36 |
// @Value("${mybatis-plus.mapper-locations}") |
|
37 |
// private String mapperLocations; |
|
38 |
// |
|
39 |
// @Bean |
e7c126
|
40 |
// @Primary |
d9f9ba
|
41 |
// public SqlSessionFactory sqlSessionFactory() throws Exception { |
H |
42 |
// SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); |
|
43 |
// sqlSessionFactoryBean.setDataSource(DataSourceBuilder.create().build()); |
|
44 |
// sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations)); |
|
45 |
// sqlSessionFactoryBean.setConfiguration(buildConfiguration()); |
|
46 |
// return sqlSessionFactoryBean.getObject(); |
e7c126
|
47 |
// } |
d9f9ba
|
48 |
// |
H |
49 |
// @Bean |
|
50 |
// @Primary |
|
51 |
// public SqlSessionTemplate sqlSessionTemplate() throws Exception { |
|
52 |
// return new SqlSessionTemplate(sqlSessionFactory()); |
|
53 |
// } |
|
54 |
// |
|
55 |
// @Bean |
|
56 |
// @Primary |
|
57 |
// public DataSourceTransactionManager transactionManager() { |
|
58 |
// return new DataSourceTransactionManager(DataSourceBuilder.create().build()); |
|
59 |
// } |
|
60 |
// |
|
61 |
// private org.apache.ibatis.session.Configuration buildConfiguration() { |
|
62 |
// org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(); |
|
63 |
// configuration.getTypeHandlerRegistry().register(JSONObject.class, JdbcType.VARCHAR, MybatisHandler.class); |
|
64 |
// configuration.getTypeHandlerRegistry().register(JSONArray.class, JdbcType.VARCHAR, MybatisHandler.class); |
|
65 |
// return configuration; |
|
66 |
// } |
|
67 |
// |
|
68 |
// @Bean |
|
69 |
// public MybatisPlusInterceptor mybatisPlusInterceptor() { |
|
70 |
// MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); |
|
71 |
// // 数据权限 |
|
72 |
// mybatisPlusInterceptor.addInnerInterceptor(new DataFilterInterceptor()); |
|
73 |
// // 分页插件 |
|
74 |
// mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor()); |
|
75 |
// // 乐观锁 |
|
76 |
// mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); |
|
77 |
// // 防止全表更新与删除 |
|
78 |
// mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor()); |
|
79 |
// |
|
80 |
// return mybatisPlusInterceptor; |
|
81 |
// } |
|
82 |
// |
|
83 |
// |
|
84 |
//} |