报错类型
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'age' not found. Available parameters are [arg1, arg0, param1, param2]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
at com.sun.proxy.$Proxy56.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForIPage(MybatisMapperMethod.java:122)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:87)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInv
错误场景
Mapper.xml 代码
<select id="selectPageByAge" resultType="com.atguigu.mubatisplus.entity.User">
select <include refid="Base_Column_List"/>
from t_user
where age > #{age}
</select>
测试代码
@Test
public void testSelectPageByAge(){
Page<User> page = new Page<>(1,10);
//查询年龄大于25的用户
userMapper.selectPageByAge(page, 20);
List<User> userList = page.getRecords();
userList.forEach(System.out::println);
}
解决方法
将mapper.xml代码更改为:
<select id="selectPageByAge" resultType="com.atguigu.mubatisplus.entity.User">
select <include refid="Base_Column_List"/>
from t_user
where age > #{arg1}
</select>
即最后一句: #{age} --> #{arg1}或者#{arg0}