### Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [arg1, arg0, param1, param2]

org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [arg1, arg0, param1, param2]
### The error may involve com.imp.IStudents.insertOne-Inline
### The error occurred while setting parameters
### SQL: insert into students(name,pass) values(?,?)
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [arg1, arg0, param1, param2]

mmp ,遇到这个错误弄了半天,在百度上找了半天的教程,在cdsn上看到说是有两种方法可以

但我测试之后只有第一种方法可行

xml文件中的插入语句不要变

   <insert id="insertOne" parameterType="Students">
insert into students(name,age) values(#{name},#{age})
</insert>

改一下接口中的方法的参数

  void insertOne(@Param("name")String name,@Param("age")int age);

IStudents.java

测试方法如下

 @Test
public void testInsertOne() throws Exception {
SqlSession sqlSession = DataBaseManager.getSqlSession();
IStudents mapper = sqlSession.getMapper(IStudents.class);
mapper.insertOne("邢逸", 18);
sqlSession.commit();
}

TestBasic.java

上一篇:《UNIX/Linux网络日志分析与流量监控》新书发布


下一篇:acdream 1738 世风日下的哗啦啦族I