報錯類型
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}