1、controller层的分页查询方法中参数pageRequest接收不到前台,传递的int page和int size参数,并提示没有相应的构造
public ResponseEntity<Page<User>> queryByPage(User user,PageRequest pageRequest)
原因:PageRequest 所在包升级废弃了该类的构造
解决方案:如下
public ResponseEntity<Page<User>> queryByPage(User user, @RequestParam("page") int pageIndex,@RequestParam("size") int pageSize)
2、controller层的分页查询方法,在dao层访问数据库时,提示未找到对应的#{id},而id实际上为user对象的属性,由于有入参有两个对象
List<User> queryAllByLimit(User user, @Param("pageable") Pageable pageable);
问题的原因:由于有入参有两个对象,需要指定两个对象的名称,且在xml文件中需要通过#{user.id}的方式获取属性
List<User> queryAllByLimit(@Param("user")User user, @Param("pageable") Pageable pageable);
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="BaseResultMap">
select
id, stuId, name, age, sex, address, country, city, salary
from user
<where>
<if test="user.id != null">
and id = #{user.id}
</if>
<if test="user.stuid != null">
and stuId = #{user.stuid}
</if>
<if test="user.name != null and user.name != ''">
and name = #{user.name}
</if>
<if test="user.age != null">
and age = #{user.age}
</if>
<if test="user.sex != null and user.sex != ''">
and sex = #{user.sex}
</if>
<if test="user.address != null and user.address != ''">
and address = #{user.address}
</if>
<if test="user.country != null and user.country != ''">
and country = #{user.country}
</if>
<if test="user.city != null and user.city != ''">
and city = #{user.city}
</if>
<if test="user.salary != null">
and salary = #{user.salary}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>