实体类与数据库表中字段不一致时,相应的注解
1. 与数据库表对应的PO.class
@Transient
特别强调:不是数据库表字段的属性必须加@Transient注解(import javax.persistence.Transient;)
@Column
数据库表字段与result不一致时用@Column注解,例如:
@Column(name = "f_schema")
private String schema;
2. 传入参数与数据库表字段不一致:
@Param
下面举个例子
表字段f_schema与实体schema不一致 错误代码:
@Update({ "<script> update user_extra_info "
+ "<set> version=version+1, info='${info}',f_schema='${schema}' </set>"
+ "where uid='${uid}'"
+ " and appid='${appid}' "
+ "and version='${version}' </script>"})
public int update(UserExtraInfo info);
表字段f_schema与实体schema不一致 正确代码:
@Update({ "<script> update user_extra_info "
+ "<set> version=version+1, info='${info.info}',f_schema='${info.schema}' </set>"
+ "where uid='${info.uid}'"
+ " and appid='${info.appid}' "
+ "and version='${info.version}' </script>"})
public int update(@Param("info") UserExtraInfo info);