赞
踩
/**
* @ClassName PageVo
* @Description T0D0
* @Author cc
* @Date 2022/3/28 13:00
* @Version 1.0
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageVo<T> {
private Integer total;//总条数
private List<T> dataList;//数据
private Integer currentPage;//当前页数
private Integer pageSize;//当前页面条数
}
@GetMapping("/page/search")
public CommonResult search(@RequestParam(defaultValue = "1")Integer currentPage,
@RequestParam(defaultValue = "8") Integer pageSize,
@RequestParam(defaultValue = "") String keywords){
PageVo<Spot> page = spotService.getPage(currentPage, pageSize,keywords);
if(page!=null){
return new CommonResult(SysContains.httpOk,"查询成功",page);
}
return new CommonResult(SysContains.queryFailed,"查询失败");
}
@Override
public PageVo<Spot> getPage(Integer currentPage, Integer pageSize, String keywords) {
//因为前端传过来的currentPage是从1开始,而数据库limit是从0开始,所以需要减一
currentPage = currentPage - 1;
Integer total = spotMapper.selectSpotCount();//根据自己需要,查询总条数
List<Spot> dataList = spotMapper.getPage(currentPage, pageSize, keywords);
PageVo<Spot> pageVo = new PageVo<>();
pageVo.setTotal(total);//设置总条数
pageVo.setDataList(dataList);//设置查询数据
pageVo.setCurrentPage(currentPage + 1);//设置页面显示当前页,之前减了1,需要加上,反馈给前端
pageVo.setPageSize(pageSize);//设置页面当前显示条数
return pageVo;
}
<select id="getPage" resultType="com.cc.entity.Spot">
select s.id,s.name,s.pic,s.introduction,s.duration,s.director,s.director_phone directorPhone,
s.resource,s.address,s.created_time createdTime,s.remarks,s.is_hot isHot,s.created_user_id createdUserId from
spot s
<where>
<if test="keywords !=null and keywords !=''">
or `name` like '%' #{keywords} '%'
</if>
<if test="keywords !=null and keywords !=''">
or `address` like '%' #{keywords} '%'
</if>
</where>
limit #{currentPage},#{pageSize}
</select>
<select id="selectSpotCount" resultType="java.lang.Integer">
select count(1) from spot
<where>
<if test="keywords!=null and keywords!=''">
or address like '%' #{keywords} '%'
</if>
<if test="keywords!=null and keywords!=''">
or `name` like '%' #{keywords} '%'
</if>
</where>
</select>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。