<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="UserMap">
select
uid, username, password, level
from user
<where>
<if test="uid != null">
and uid = #{uid}
</if>
<if test="username != null and username != ''">
and username = #{username}
</if>
<if test="password != null and password != ''">
and password = #{password}
</if>
<if test="level != null and level != ''">
and level = #{level}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
测试代码:
User user = new User();
user.setUsername("www");
userService.queryByPage(user, new PageRequest(1,100));
报错:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'uid' not found. Available parameters are [arg0, pageable, param1, param2]
怀疑是dao中同时传入了user和pageable导致无法识别
如下修改解决问题
给dao.java的实体类加Param注解List<User> queryAllByLimit(@Param("user") User user, @Param("pageable") Pageable pageable);
用插件的Default模板,在以实体类为条件进行查询时,出现参数异常
插件版本:1.2.6
Mybatis版本:3.5.9
代码如下
实体类:
dao:
xml:
测试代码:
报错:
怀疑是dao中同时传入了user和pageable导致无法识别
如下修改解决问题
给dao.java的实体类加Param注解
List<User> queryAllByLimit(@Param("user") User user, @Param("pageable") Pageable pageable);
在dao.xml中修改,使用【引用.属性名】的方式访问,如:
项目使用的是ssm框架,不知道是不是我调用出现了问题?