@Transient //忽略映射关系
private Integer age; //表示表中没有这个字段
当使用快速开发,表与实体类进行绑定时,可以使用 @Transient注解实现实体类中没有的字段。
例如:
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "smbms_user")
public class SmbmsUser {
@Id@KeySql(useGeneratedKeys = true)
private Integer id;
private String usercode;
private String username;
private String userpassword;
private Integer gender;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birthday;
private String phone;
private String address;
private Long userrole;
private Long createdby;
private Date creationdate;
private Long modifyby;
private Date modifydate;
//当知道出生年月日,能不能得到年龄 1998 2022
@Transient //忽略映射关系
private Integer age; //表示表中没有这个字段
public Integer getAge() {
//计算年龄
Calendar newDate=Calendar.getInstance();
Calendar birth=Calendar.getInstance();
birth.setTime(birthday);
return newDate.get(Calendar.YEAR)-birth.get(Calendar.YEAR);
}
}