我的 java pojo 中有一个整数数组 int[] 大小。我将其作为大小 integer[] 存储在 postgres 中。我正在尝试使用 mybatis 使用结果映射来映射它,例如:
<resultMap id="result" type="javaPojo">
<result column="sizes" jdbcType="ARRAY" property="sizes"/>
</resultMap>
每次我收到如下错误时:
Error parsing SQL Mapper Configuration, Cause java.lang.IllegalStateException: No typehandler found for property sizes.
所有内容都是使用 java 程序生成的,由于公司政策,我无法透露。
最佳答案
收到此错误是因为 typeHandlers 不支持 int[]。更详细的mybatis支持类型可以引用:Type Handlers Mybatis .
现在我为您提供了 2 个解决方案。
创建新的类型处理程序 here .
更改
int[]
至List<Integer>
.
示例代码:
只需将 resultType 声明为您想要的原始类型,在您的情况下是 Integer。它将作为列表返回。
<select id="getPrice" resultType="java.lang.Integer">
select product_price from products
</select>
在映射器界面中,您应该会返回一个 Long 列表。
List<Integer> getPrice();
我从这个 link 克隆上面的例子
关于java - 如何使用mybatis在postgres中将int[]映射到integer[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57519542/