1. Mapper.xml别名爆红,程序运行没问题
可能由于你装了上述IDEA插件导致的
? ?
解决方案
2. xml重写selectPage模板方法,导致QueryWrapper.lambda后面的查询条件失效
改成Bean对象入参
? ?
3. Model继承问题 - 多加一个BaseModel(用于标识公共字段)
BaseDB.java
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class BaseDB<T extends BaseDB<?>> extends Model<T> {
private static final long serialVersionUID = 3253505422347170166L;
@TableId
private String id;
@TableField(fill = FieldFill.INSERT)
private String createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateTime;
@TableField
@TableLogic
private Integer isDel;
@TableField
@Version
private Integer version;
}
? ? SysUser.java
@Data
@ToString(callSuper=true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@TableName("sys_user")
public class SysUser extends BaseDB<SysUser> implements Serializable {
private static final long serialVersionUID = 2095940921263481761L;
private String nickName;
private String headUrl;
private String loginName;
private String phoneNumber;
private String email;
private Integer gender;
private String personalMotto;
private String lastLoginTime;
private Integer loginStatus;
private Integer disabledStatus;
private String password;
}
? ?
4. Wrapper的优先级高于实体
MyMetaObjectHandler.java
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "createTime", String.class, DatePattern.NORM_DATETIME_FORMATTER.format(LocalDateTime.now()));
this.strictInsertFill(metaObject, "updateTime", String.class, DatePattern.NORM_DATETIME_FORMATTER.format(LocalDateTime.now()));
}
@Override
public void updateFill(MetaObject metaObject) {
this.strictUpdateFill(metaObject, "updateTime", String.class, DatePattern.NORM_DATETIME_FORMATTER.format(LocalDateTime.now()));
}
}
? ?
test5.java
@Test
public void test5() {
boolean updateFlag = new SysUser().setUpdateTime(DatePattern.NORM_DATETIME_FORMAT.format(DateUtil.endOfMonth(new Date())))
.update(Wrappers.<SysUser>lambdaUpdate()
.set(SysUser::getEmail, "2329073340@qq.com")
.set(SysUser::getUpdateTime, DatePattern.NORM_DATETIME_FORMAT.format(DateUtil.beginOfMonth(new Date())))
.eq(SysUser::getId, "6d72c93aa292cf2ca2e789919a5e7bdc"));
Console.log("更新状态:{}", updateFlag);
}
? ?
5. @Version - 仅以实体生效
update 表 set version = version + 1 where version = version实体字段值
否则只会生成一个where或者set版本值
会有两个set version版本值 以及两个 where 版本值
? ?
6. 构建条件
如果实体以及wrapper都设置了对应的字段值,则会同时两个都会生成,而不会去重优先选一个
|