gpt4 book ai didi

java - mybatis 插入带有列表的嵌套 pojo

转载 作者:行者123 更新时间:2023-12-02 04:34:20 30 4
gpt4 key购买 nike

我有嵌套的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>

关于java - mybatis 插入带有列表的嵌套 pojo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56559461/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com