提交 | 用户 | 时间
|
a6316e
|
1 |
package com.billion.framework.config; |
A |
2 |
|
|
3 |
import com.baomidou.mybatisplus.annotation.DbType; |
9f7aa7
|
4 |
import com.baomidou.mybatisplus.core.config.GlobalConfig; |
a6316e
|
5 |
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
A |
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 org.springframework.context.annotation.Bean; |
|
10 |
import org.springframework.context.annotation.Configuration; |
|
11 |
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
12 |
|
|
13 |
/** |
|
14 |
* Mybatis Plus 配置 |
|
15 |
* |
|
16 |
* @author ruoyi |
|
17 |
*/ |
|
18 |
@EnableTransactionManagement(proxyTargetClass = true) |
|
19 |
@Configuration |
|
20 |
public class MybatisPlusConfig |
|
21 |
{ |
|
22 |
@Bean |
|
23 |
public MybatisPlusInterceptor mybatisPlusInterceptor() |
|
24 |
{ |
|
25 |
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
|
26 |
// 分页插件 |
|
27 |
interceptor.addInnerInterceptor(paginationInnerInterceptor()); |
|
28 |
// 乐观锁插件 |
|
29 |
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); |
|
30 |
// 阻断插件 |
|
31 |
interceptor.addInnerInterceptor(blockAttackInnerInterceptor()); |
|
32 |
return interceptor; |
|
33 |
} |
|
34 |
|
9f7aa7
|
35 |
@Bean |
吴 |
36 |
public GlobalConfig globalConfig() { |
|
37 |
GlobalConfig globalConfig = new GlobalConfig(); |
|
38 |
globalConfig.setMetaObjectHandler(new MyMetaObjectHandler()); // 设置MetaObjectHandler |
|
39 |
return globalConfig; |
|
40 |
} |
|
41 |
|
a6316e
|
42 |
/** |
A |
43 |
* 分页插件,自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html |
|
44 |
*/ |
|
45 |
public PaginationInnerInterceptor paginationInnerInterceptor() |
|
46 |
{ |
|
47 |
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); |
|
48 |
// 设置数据库类型为mysql |
|
49 |
paginationInnerInterceptor.setDbType(DbType.MYSQL); |
|
50 |
// 设置最大单页限制数量,默认 500 条,-1 不受限制 |
|
51 |
paginationInnerInterceptor.setMaxLimit(-1L); |
|
52 |
return paginationInnerInterceptor; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* 乐观锁插件 https://baomidou.com/guide/interceptor-optimistic-locker.html |
|
57 |
*/ |
|
58 |
public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() |
|
59 |
{ |
|
60 |
return new OptimisticLockerInnerInterceptor(); |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* 如果是对全表的删除或更新操作,就会终止该操作 https://baomidou.com/guide/interceptor-block-attack.html |
|
65 |
*/ |
|
66 |
public BlockAttackInnerInterceptor blockAttackInnerInterceptor() |
|
67 |
{ |
|
68 |
return new BlockAttackInnerInterceptor(); |
|
69 |
} |
|
70 |
} |