1,常用注解
@TableName 映射数据表表名和实体对象类名
@TableId 注明表id
@TableField 映射数据表字段名和实体对象属性名
@TableLogic 用作逻辑删除,需要搭配配置文件使用
【注意】
逻辑删除生效的前提条件:
1,适用修改,删除,查询语句
2,只有调用mybatis封装的工具类时
3,为了确保新增的正常,数据库需要设置is_delete字段的默认值
更多逻辑删除知识点:https://blog.csdn.net/qq_43437874/article/details/115318334
@TableName(value ="t_user")
@Data
@Accessors(chain = true)//开启链式
public class UserInfo implements Serializable {
/**
* id
*/
@TableId(value = "id",type = IdType.AUTO)
private String id;
/**
* 用户名
*/
@TableField(value = "user_name")
private String name;
/**
* 是否删除
*/
@TableField(value = "is_delete")
@TableLogic
private Integer isDelete;
}
2,常用配置
mybatis-plus:
mapper-locations: classpath:/mapper/*.xml #设置mapper xml文件路径
global-config:
db-config:
id-type: ASSIGN_UUID #全局设置主键类型
table-underline: true #开启驼峰配置
logic-delete-field: is_delete # 全局逻辑删除的实体字段名
logic-not-delete-value: 0 # 未删除设置0
logic-delete-value: 1 # 已删除设置0
table-prefix: t_ #全局设置表名前缀,针对有规律的表名,这样可以不用@TableName
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl#开启sql语句日志打印