Controller层
@ApiOperation(value = "多条件查询")
@PostMapping("/personnelApplication/query")
public ApiRestResponse query(@RequestBody @Valid queryPersonnelApp queryPersonnelApp){
return ApiRestResponse.success(ryzsJbxx.query(queryPersonnelApp));
}
queryPersonnelApp类是查询需要传的参数,如下:
package com.lbcc.mall.model.request;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
public class queryPersonnelApp {
private String name;
private Integer pageNum=1;
private Integer pageSize=10;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public Integer getPageNum() {
return pageNum;
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
}
Service层
PageBean<RyzsJbxx> query(queryPersonnelApp queryPersonnelApp);
实现service的impl中进行数据的查询:
@Override
public PageBean<RyzsJbxx> query(queryPersonnelApp queryPersonnelApp) {
PageHelper.startPage(queryPersonnelApp.getPageNum(),queryPersonnelApp.getPageSize());
RyzsJbxx ryzsJbxx = new RyzsJbxx();
BeanUtils.copyProperties(queryPersonnelApp,ryzsJbxx);
List<RyzsJbxx> list = ryzsJbxxMapper.query(ryzsJbxx);
PageBean<RyzsJbxx> info = new PageBean<>(list);
return info;
}
注意:这里你要是用pageinfo的话给前端返回的值可能有些多余,因为有些参数前端不需要,所以这里的pageBean是重构了一下pageinfo的返回数据参数,在这里我是这样写的:
package com.lbcc.mall.model.request;
import com.github.pagehelper.Page;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
public class PageBean<T> implements Serializable {
private static final long serialVersionUID = 1L;
private int pageNum;
private int pageSize;
private int size;
private long total;
private int pages;
private List<T> list;
public PageBean(List<T> list) {
this(list, 8);
}
public PageBean(List<T> list, int navigatePages) {
if (list instanceof Page) {
Page page = (Page)list;
this.pageNum = page.getPageNum();
this.pageSize = page.getPageSize();
this.pages = page.getPages();
this.list = page;
this.size = page.size();
this.total = page.getTotal();
} else if (list instanceof Collection) {
this.pageNum = 1;
this.pageSize = list.size();
this.pages = this.pageSize > 0 ? 1 : 0;
this.list = list;
this.size = list.size();
this.total = (long)list.size();
}
}
public int getPageNum() {
return this.pageNum;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public int getPageSize() {
return this.pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getSize() {
return this.size;
}
public void setSize(int size) {
this.size = size;
}
public long getTotal() {
return this.total;
}
public void setTotal(long total) {
this.total = total;
}
public int getPages() {
return this.pages;
}
public void setPages(int pages) {
this.pages = pages;
}
public List<T> getList() {
return this.list;
}
public void setList(List<T> list) {
this.list = list;
}
public String toString() {
StringBuffer sb = new StringBuffer("PageBean{");
sb.append("pageNum=").append(this.pageNum);
sb.append(", pageSize=").append(this.pageSize);
sb.append(", size=").append(this.size);
sb.append(", total=").append(this.total);
sb.append(", pages=").append(this.pages);
sb.append(", list=").append(this.list);
sb.append(", navigatepageNums=");
sb.append('}');
return sb.toString();
}
}
mapper中:
List<RyzsJbxx> query(RyzsJbxx ryzsJbxx);
xml中,:
<select id="query" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from lbcc_ryzs_jbxx
<where>
<if test="name!=null">
and name like CONCAT('%',#{name},'%')
</if>
</where>
</select>
|