mybatisplus全局配置
时间: 2023-09-27 08:11:37 浏览: 51
MybatisPlus的全局配置包括基本配置和进阶配置。基本配置是指在mybatis-config.xml文件中对MybatisPlus进行配置,可以参考官方文档中的基本配置部分进行配置。而进阶配置包括了多个方面,如通用CRUD操作、条件构造器、ActiveRecord的使用、常用插件的使用、逻辑删除、通用枚举的实现以及代码生成器等。
在Spring Boot中,可以通过在application.yml文件中添加相应的配置来实现MybatisPlus的全局配置。例如,通过配置mapper-locations属性可以指定mapper文件的位置,通过配置type-aliases-package属性可以指定实体类的包路径,还可以通过configuration属性来进行属性与表字段的映射配置。
总之,MybatisPlus的全局配置可以通过配置文件进行配置,包括基本配置和进阶配置,这些配置可以根据具体需求来进行灵活的设置。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
相关问题
mybatisPlus pgsql配置
在yml配置文件中,需要添加如下配置:
```
server:
port: 8080
spring:
application:
name: xxxx
datasource:
dynamic:
primary: pgsql #设置默认的数据源或者数据源组,默认值即为pgsql
strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
datasource:
pgsql:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://192.168.1.167:5432/aaa?currentSchema=aaa
username: aaa
password: aaa
mysql:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/bbb?useUnicode=true&characterEncoding=utf8
username: bbb
password: bbb
mybatis-plus:
type-aliases-package: com.dms.gateway.api.entity
mapper-locations: classpath:/mapper/*Mapper.xml
global-config:
db-config:
id-type: auto
field-strategy: not_empty
logic-delete-value: 1
logic-not-delete-value: 0
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
call-setters-on-nulls: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
```
其中,需要注意的是,需要在`spring.datasource.dynamic`下设置默认的数据源或者数据源组,即`primary`属性,这里设置为`pgsql`。同时,需要在`spring.datasource.datasource`下配置`pgsql`数据源的相关信息,包括`driver-class-name`、`url`、`username`和`password`等。
另外,需要在`mybatis-plus.global-config`下配置相关的全局配置信息,包括`id-type`、`field-strategy`、`logic-delete-value`、`logic-not-delete-value`等。
mybatisplus 怎么配置插件
Mybatis-Plus 是 Mybatis 的一个插件,它简化了 Mybatis 的一些操作,提高了开发效率。Mybatis-Plus 的插件可以通过配置文件来进行配置。下面是一个示例:
```yaml
mybatis-plus:
configuration:
map-underscore-to-camel-case: true # 下划线转驼峰
global-config:
db-config:
logic-delete-field: deleted # 逻辑删除字段名
logic-delete-value: 1 # 逻辑删除值
logic-not-delete-value: 0 # 逻辑未删除值
plugins:
- com.baomidou.mybatisplus.plugins.PaginationInterceptor # 分页插件
- com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor # 乐观锁插件
```
在上述配置中,我们可以看到 Mybatis-Plus 的插件都定义在 `plugins` 中,每个插件需要指定其全限定类名。在这里,我们配置了 Mybatis-Plus 的两个常用插件:分页插件和乐观锁插件。此外,我们还可以通过 `global-config` 配置逻辑删除相关的信息,通过 `configuration` 配置 Mybatis 的全局配置。
需要注意的是,不同版本的 Mybatis-Plus 的插件类名可能有所不同,需要根据版本来进行调整。另外,Mybatis-Plus 还支持自定义插件,可以根据具体需求来编写自己的插件,然后将其配置到 `plugins` 中即可。