解决Postgresql varchar[] 数组类型导致的MybatisPuls查询为null的解决方案
某业务需求
某表新建了数组类型的字段
ALTER TABLE "public"."product_recommend"
ADD COLUMN "tags" varchar[];
java实体类为
private String[] tags;
但如果直接查询,即使数据库有数据,也无法查询出来,我们需要稍作处理
import org.apache.ibatis.type.ArrayTypeHandler;
class ProductRecommend{
@TableField(typeHandler = ArrayTypeHandler.class)
private String[] tags;
}
我们需要指定apache的ArrayTypeHandler
当使用mybatisPlus自带的方法就可以查询出来
但使用xml查询依旧不行,我们需要在xml文件单独处理
<resultMap id="selectFindPageMap" type="xxx.VO">
<result column="tags" property="tags" jdbcType="ARRAY" typeHandler="org.apache.ibatis.type.ArrayTypeHandler"/>
</resultMap>
<select id="selectFindPage"
resultMap="selectFindPageMap">
select * from product_recommend
</select>
完美解决