2016-09-19 18 views
0

我的類別字段看起來像如何使用MyBatis的批註插入簡單數組表字段

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

我InnoDB表看起來像

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

我嘗試插入行表thith這個映射器(I」米使用註釋)

@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機會。

回答

0

我看到片段的MyBatis的參數輸入錯誤,在大括號{}:

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

此外,可以要求定製ArrayTypeHandler實現,無論是這裏的格式被存儲爲一個字符串( Varchar),或者如果它存儲爲SQL Array,則依賴於環境:數據庫類型/驅動程序,池連接,應用程序服務器...

相關問題