在Springboot+Mybatis学习过程中出现的问题:
在SpringBoot项目中用MyBatis框架实现分页时,运行报错:如下
org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [arg3, arg2, arg1, arg0, param3, param4, param1, param2]
原来出现问题的Mapper
//获取当前页的结果列表
public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);
解决:
需要再Dao层(Mapper层)添加@Param()注解
//获取当前页的结果列表
public List<Emp> list(@Param("name") String name, @Param("gender") Short gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);
@Param
是MyBatis所提供的作为Dao层的注解,作用是用于传递参数,从而可以与SQL中的的字段名相对应。
注解 | 来源 |
@Param | org.apache.ibatis.annotations.Param |