配置文件
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #输出sql日志
mapper-locations: classpath:com/example/dao/*.xml #对应xml的路径
global-config:
db-config:
id-type: auto #自增id
field-strategy: not_empty
#驼峰下划线转换
column-underline: true
#逻辑删除配置
logic-delete-value: 0
logic-not-delete-value: 1
db-type: mysql
refresh: false
实体类注解
1.@TableName
类型 | 内容 | 默认值 |
---|---|---|
value | 实体对应的表名 | “” |
schema | “” | |
keepGlobalPrefix | 是否保持使用全局的 tablePrefix 的值 | false |
resultMap | 实体映射结果集 | “” |
autoResultMap | 是否自动构建 resultMap 并使用 | false |
- @TableId
类型 | 内容 | 默认值 |
---|---|---|
value | 字段值(驼峰命名方式,该值可无) | null |
type | 主键ID | IdType.NONE(该类型为未设置主键类型(将跟随全局)) |
type值为:
- IdType.AUTO:数据库ID自增
- IdType.NONE:该类型为未设置主键类型(将跟随全局)
- IdType.INPUT:用户输入ID
- IdType.ID_WORKER:全局唯一ID (idWorker)
- IdType.UUID:全局唯一ID (UUID)
- IdType.ID_WORKER_STR:字符串全局唯一ID (idWorker 的字符串表示)
- @TableField
类型 | 内容 | 默认值 |
---|---|---|
value | 字段值(驼峰命名方式,该值可无 ) | null |
exist | 是否为数据库表字段 默认 true 存在,false 不存在(sql中不添加此参数) | true |
condition | 字段 where 实体查询比较条件 默认 = 等值 | null |
update | 字段 update set 部分注入, 该注解优于 el 注解使用 | null |
insertStrategy | 字段验证策略之 insert | FieldStrategy.DEFAULT |
updateStrategy | 字段验证策略之 update | FieldStrategy.DEFAULT |
whereStrategy | 字段验证策略之 where | FieldStrategy.DEFAULT |
fill | 字段自动填充策略 | FieldStrategy.DEFAULT |
select | 是否进行 select 查询 | true |
keepGlobalFormat | 是否保持使用全局的 Format 的值 | false |
jdbcType | JDBC类型 (该默认值不代表会按照该值生效) | JdbcType.UNDEFINED |
typeHandler | 类型处理器 (该默认值不代表会按照该值生效) | UnknownTypeHandler.class |
numericScale | 指定小数点后保留的位数 | null |
- @Version 乐观锁
实体类和数据库需定义字段,会一步一步迭代,需注入bean
@Bean
public OptimisticLockerInterceptor optimisticLockerInterceptor(){
return new OptimisticLockerInterceptor();
}
- @EnumValue
枚举类型,可使框架自动对应内容;
例如:数据库中是1 ------》框架会自动对应 男
One(1,"就绪"),
Two(2,"等待"),
Three(3,"小休"),
Four(4,"通话中"),
Five(5,"话后处理"),
Six(6,"下班");
StudentEnums(Integer code, String content) {
this.code = code;
this.content = content;
}
@EnumValue
private Integer code;
@JsonValue
private String content;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
注:需实现get,set方法以及用@JsonValue对应的映射(否则显示的One)
继承实现
public enum SexEnum implements IEnum<Integer> {
One(1,"男"),
women(2,"女"),
none(3,"未添加");
SexEnum(Integer code, String content) {
this.code = code;
this.content = content;
}
@EnumValue
private Integer code;
@JsonValue
private String content;
@Override
public Integer getValue() {
return this.code;
}
}
- @TableLogic
实现逻辑删除
配置文件中需配置
#逻辑删除配置
#设置0为删除时的状态
logic-delete-value: 0
#设置1为未删除时的状态
logic-not-delete-value: 1
要dome工程的,私信