实体类:
@Data
@TableName(value = "centre_manage_server_info")
public class ServerEntity {
@TableId(value = "id")
//@Column(name = "id", isKey = true, isNull = false, comment = "id" )
private String id;
/**
* 服务器ip
*/
@TableField(value = "ip", insertStrategy = FieldStrategy.NOT_EMPTY)
//@Column(name = "ip", isNull = false, comment = "服务器ip" )
private String ip;
/**
* 服务器port
*/
@TableField(value = "port", insertStrategy = FieldStrategy.NOT_NULL)
//@Column(name = "port", isNull = false, comment = "服务器port" )
private Integer port;
/**
* 服务器登录用户名
*/
@TableField(value = "authentication_name", typeHandler = AesTypeHandler.class, insertStrategy = FieldStrategy.NOT_EMPTY)
//@Column(name = "authentication_name", isNull = false, comment = "服务器登录用户名" )
private String authenticationName;
/**
* 服务器登录密码
*/
@TableField(value = "authentication_pwd", typeHandler = AesTypeHandler.class, insertStrategy = FieldStrategy.NOT_EMPTY)
//@Column(name = "authentication_pwd", isNull = false, comment = "服务器登录密码" )
private String authenticationPwd;
}
结果插入时时有效的,但是i查询时会出现部分没有解密的问题。
解决:
1.实体类注解TableName 补充 autoResultMap = true
@TableName(value = "centre_manage_server_info", autoResultMap = true)
2. mapper.xml的resultMap也需要
<resultMap id="ServerEntity" type="com.zhong.core.centremanage.dbservice.server.entity.ServerEntity">
<id column="id" property="id" />
<result column="ip" property="ip" />
<result column="port" property="port" />
<result column="authentication_name" property="authenticationName" typeHandler="xxxx.AesTypeHandler"/>
<result column="authentication_pwd" property="authenticationPwd" typeHandler="xxxx.AesTypeHandler"/>
</resultMap>