这里的fill值可以填充如下内容,见名就可以思意
public enum FieldFill {
DEFAULT,
INSERT,
UPDATE,
INSERT_UPDATE;
private FieldFill() {
}
}
public void insertFill(MetaObject metaObject)
public void updateFill(MetaObject metaObject)
public String[] getGetterNames()
public String[] getSetterNames()
public Class> getSetterType(String name)
public Class> getGetterType(String name)
public boolean hasSetter(String name)
public boolean hasGetter(String name)
public Object getValue(String name)
@Data
public class User extends Model
private Long id;
private String name;
private Integer age;
private String email;
private int deleted;
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime createtime;
}
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
System.out.println("insertFill");
setFieldValByName("createtime", LocalDateTime.now(),metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
System.out.println("updateFill");
setFieldValByName("createtime", LocalDateTime.now(),metaObject);
}
}
@Test
public void testSave(){
for(long i=12;i<13;i++) {
User user = new User();
user.setId(400+i);
user.setAge((int)i+30);
user.setEmail("zoulinlin"+i+"@163.com");
user.setName("zouli"+i);
int row = userMapper.insert(user);
System.out.println(row);
}
}
insertFill
2022-10-10 14:23:58.740 DEBUG 2588 --- [ main] c.m.service.mapper.UserMapper.insert : ==> Preparing: INSERT INTO user ( id, name, age, email, deleted, createtime ) VALUES ( ?, ?, ?, ?, ?, ? )
2022-10-10 14:23:58.767 DEBUG 2588 --- [ main] c.m.service.mapper.UserMapper.insert : ==> Parameters: 412(Long), zouli12(String), 42(Integer), [email protected](String), 0(Integer), 2022-10-10T14:23:56.361(LocalDateTime)
2022-10-10 14:23:58.915 DEBUG 2588 --- [ main] c.m.service.mapper.UserMapper.insert : <== Updates: 1
1
@Test
public void testUpate(){
UpdateWrapper
updateWrapper.eq("id",2) ;
User user=new User();
user.setName("zzzz");
user.setAge(100);
userMapper.update(user,updateWrapper);
}
@Test
public void testUpate(){
UpdateWrapper
updateWrapper.eq("id",2) ;
User user=new User();
user.setName("zzzz");
user.setAge(100);
userMapper.update(user,updateWrapper);
}