spring+mybatis3.3.0进行批量insert报错

千山独行 千山独行 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
使用的框架是spring 4.1.x + mybatis-spring 1.2.3 + mybatis 3.3.0

pojo类很简单

public class Person implements Serializable{
/**
*
*/
private static final long serialVersionUID = -8882286452255354656L;
//主键
private Long id;

private String firstname;

private String lastname;

private String school;

... ...
}

PersonMapper.java中写了一个批量insert的方法

void batchInsert( @Param("list") List<Person> persons);

然后在.xml里的配置如下:

<insert id="batchInsert" keyProperty="id" useGeneratedKeys="true" parameterType="java.util.List">
insert into person (firstName, lastName,school) values
<foreach collection="list" item="person" index="index" separator="," >
(#{person.firstName},#{person.lastName},#{person.school})
</foreach>
</insert>

在测试这个方法时,提示下面的错误:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch_person_0' not found. Available parameters are [list, param1]

如果注释掉PersonMapper.java中@Param("list")这部分,则是

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch_person_0' not found. Available parameters are [collection, list]

注意最后这部分提示不太一样,最近刚开始用mybatis,哪位大神给看看,
这个错误该怎么办

另外,对其他的select,insert方法进行测试都正确。
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
千山独行
Java EE 67,535 成员 225,843 内容