这是我的模型Admin:
@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Admin {
@NotNull
@Column(unique = true)
private String name;
@NotNull
private String password;
@NotNull
@DateTimeFormat(style = "M-")
private Timestamp createTime;
@Transactional
public void persist(){
if (this.entityManager == null) this.entityManager = entityManager();
this.password = DigestUtils.sha256Hex(this.password);
this.createTime = new Timestamp(new java.util.Date().getTime());
this.entityManager.persist(this);
}
}
该createTime字段有点不同,从数据库的角度来看,该字段不能为空,因为未来的业务逻辑可能会引用它,但从用户的角度来看,它永远不会出现,create admin form因为它稍后会被persist代码填充。问题是AdminController.create验证新创建的Admin对象失败,因为此时createTime仍然是null.
那么我该怎么做才能使创作Admin成功呢?