详细报错:
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'position' not found. Available parameters are [arg1, arg0, param1, param2]
报错原因:
Mapper接口中声明方法的时候有多个参数
示例:
<select id="selectUser" resultType="xxx.xxx.xxx.model.User">
select * from user where id = #{pid} and name = #{pname}
</select>
解决办法:
修改Mapper接口,使用@Param注解,这种方式Mybatis就会自动将参数封装成Map类型,@Param注解的值会作为Map中的key
拓展:
当参数为List<>集合时,也需要添加注解@Param(“xxx”)
示例:
Mapper接口中:
User selectUser(@Param("pid")String pid,@Param("pn")String pname);