org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.apache.ibatis.binding.BindingException:
Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: update students set name=? where stud_id=?
### Cause: org.apache.ibatis.binding.BindingException:
Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
public interface StudentMapper {
void updateStudentName(String name ,String id);
}
update students set name=#{0} where stud_id=#{1}
PS:顺序#{0}和Mapper接口中的参数顺序一致
@Test
public void updateStudentName() {
SqlSession sqlSession = MyBatisSqlSessionFactory.openSession();
try {
StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
studentMapper.updateStudentName("大牛",2);
sqlSession.commit();//提交,事务管理
} finally {
sqlSession.close();
}
}
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.apache.ibatis.binding.BindingException:
Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: update students set name=? where stud_id=?
### Cause: org.apache.ibatis.binding.BindingException:
Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
其中
Available parameters are [arg1, arg0, param1, param2]
含义是有效的参数是[arg1,arg0,param1,param2]
其map对应的key就是上面的这些值[arg1,arg0,param1,param2]
代码中可以通过这些名字进行引用使用
update students set name=#{arg0} where stud_id=#{arg1}
或
update students set name=#{param1} where stud_id=#{param2}
public interface StudentMapper {
void updateStudentName(@param("name1") String name,@param("id1") String id);
}
update students set name=#{name1} where stud_id=#{id1}
上传资源时候忘了传,补上内容。
DROP TABLE IF EXISTS `students`;
CREATE TABLE `students` (
`stud_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`dob` date DEFAULT NULL,
PRIMARY KEY (`stud_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
ps:源码下载 https://download.csdn.net/download/u011698550/10430282