如何使用 mybatis 注释将简单数组插入 table 字段

How to insert simple array into table field using mybatis annotation

我的 class 字段看起来像

private int[] points = new int[]{1,1,1,1};

我的 innoDb table 看起来像

CREATE TABLE `test` (
    `points` VARCHAR(70) NULL DEFAULT '0' 
)

我尝试将行插入 table 这个映射器(我正在使用注释)

@Insert({
        "REPLACE INTO test (points)",
        "values (#points},javaType=java.util.Array,typeHandler=org.apache.ibatis.type.ArrayTypeHandler)"
})

并获得 java.lang.IllegalStateException: No typehandler found for property points

如何在一个字段中正确插入这个数组? 我可以将数组转换为字符串,但我想利用 mybatis 机会。

我看到 Mybatis 参数片段中的错字,在花括号 {}:

VALUES ( {#points,javaType=java.util.Array,typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
)

此外,可能需要一个自定义的 ArrayTypeHandler 实现,要么用于格式化,因为它存储为 String(Varchar),或者如果它存储为 SQL 数组,则取决于环境:DB Type/driver、连接池、应用程序服务器...