实体类:
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "test", autoResultMap = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Test {
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> ids;
}
Mapper Xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.TestRepository">
<select id="getByPeisNoInStation" resultType="com.example.Test">
select
ids
from test
</select>
</mapper>
解决问题:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.TestRepository">
<!-- 新增-->
<resultMap id="testResultMap" type="com.example.Test">
<result column="append_package_id" jdbcType="VARCHAR" property="appendPackageId" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
</resultMap>
<!-- 新增 resultMap 属性-->
<select id="getByPeisNoInStation" resultType="com.example.Test" resultMap="testResultMap">
select
ids
from test
</select>
</mapper>
属性解释:
resultMap:
column:字段名
jdbcType:数据库字段类型
property:实体对应字段名
typeHandler:类型处理器
文章评论