MyBatis-Plus用法
service层
1、查询多个
wrapper.in(BizWorker::getId, workerIds);
in和=相似,只是一个可以查询多个结果,一个只能查询一个
2、查询某一个字段为空
wrapper.isNull(Shop::getParentId);//查询这个字段为空
3、将某个字段修改为空
for(Shop shops : shopList){
UpdateWrapper up = new UpdateWrapper<>();
up.set(“parent_id”,null);
up.eq(“id”,shops.getId());
this.update(shops,up);
}
注解
1、@TableField(exist = false) 注解加载bean属性上,表示当前属性不是数据库的字段,但在项目中必须使用,
这样在新增等使用bean的时候,mybatis-plus就会忽略这个,不会报错
2、@NotNull:不能为null,但可以为empty
3、@NotEmpty:不能为null,而且长度必须大于0
4、@NotBlank:只能作用在String上,不能为null,而且调用trim()后,长度必须大于0
5、@TableLogic逻辑删除,在实体类中加
6、@EnumValue枚举类注解(注解在枚举字段上)