[英]mybatis insert nested pojo with lists
我已經嵌套了pojos,我將這些信息插入到數據庫中。 我正在使用mybatis進行數據庫插入。
public class Student {
private List<Bike> bikes;
private long lastInsertId;
//getters and setters
}
public class Bike {
private String name;
private List<Key> bikeKeys;
//getters and setters
}
public class Key {
private String id;
private String name;
//getters and setters
}
在此之后,在mybatis映射器文件中,我插入如下,這是無效的。
<insert id="insertDetails" parameterType="com.media.domain.Student">
<foreach item="bike" index="index" collection="bikes">
<foreach item="bkItem" index="index" collection="bikeKeys">
INSERT INTO mapping(key,id,name,keyname) VALUES
(#{lastInsertId, jdbcType=INTEGER}, #{bkItem.id, jdbcType=VARCHAR}, #{bike.name, jdbcType=VARCHAR}, #{bkItem.name, jdbcType=VARCHAR});
</foreach>
</foreach>
</insert>
上面的插入語句我得到以下錯誤。
java.util.concurrent.CompletionException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'bikeKeys' in 'class com.media.domain.Student'
我可以得到一些幫助嗎? 謝謝。
為我工作的解決方案
<insert id="insertDetails" parameterType="com.media.domain.Student">
<foreach item="bike" index="index" collection="bikes">
<foreach item="bkItem" index="index" collection="bike.bikeKeys">
INSERT INTO mapping(key,id,name,keyname) VALUES
(#{lastInsertId, jdbcType=INTEGER}, #{bkItem.id, jdbcType=VARCHAR}, #{bike.name, jdbcType=VARCHAR}, #{bkItem.name, jdbcType=VARCHAR});
</foreach>
</foreach>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.