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

千山独行 2015-09-17 04:11:29
使用的框架是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方法进行测试都正确。
...全文
168 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
千山独行 2015-09-17
  • 打赏
  • 举报
回复
噢,忘记说了,数据库是mysql 5.1.x,使用的数据库驱动driver是druid 1.0.15

67,514

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧