33.高级搜索

controller

@GetMapping("/")
public RespPageBean getEmployeeByPage(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer size,
                                      Employee employee, Date[] beginDateScope) {
    return employeeService.getEmployeeByPage(page, size, employee,beginDateScope);
}

Service

public RespPageBean getEmployeeByPage(Integer page, Integer size, Employee employee,
                                      Date[] begainDateScope) {
    if (page != null && size != null) {
        page = (page - 1) * size;
    }
    List<Employee> data = employeeMapper.getEmployeeByPage(page, size, employee,begainDateScope);
    Long total = employeeMapper.getTotal(employee,begainDateScope);
    RespPageBean respPageBean = new RespPageBean();
    respPageBean.setData(data);
    respPageBean.setTotal(total);
    return respPageBean;
}

mapper

List<Employee> getEmployeeByPage(@Param("page") Integer page, @Param("size") Integer size,
                                 @Param("emp") Employee employee,
                                 @Param("beginDateScope") Date[] beginDateScope);

Long getTotal(@Param("emp")Employee employee,@Param("beginDateScope")Date[] beginDateScope);

mapper.xml

  <select id="getEmployeeByPage" resultMap="AllEmployeeInfo">
    select e.*,n.id as nid,n.`name`as nname, p.id as pid,p.name as pname,d.id as did,d.`name`as
    dname,j.id as jid,j.`name`as jname,pos.id as posid,pos.`name`as posname
 from employee e,nation n,politicsstatus p,department d,joblevel j,position pos
where e.nationId=n.id and e.politicId=p.id and
e.departmentId=d.id and e.jobLevelId=j.id and e.posId=pos.id
    <if test="emp.name !=null and emp.name!=''">
        and e.name like concat('%',#{emp.name},'%')
    </if>
    <if test="emp.politicid !=null">
      and e.politicId =#{emp.politicid}
    </if>
    <if test="emp.nationid !=null">
      and e.nationId =#{emp.nationid}
    </if>
    <if test="emp.departmentid !=null">
      and e.departmentId =#{emp.departmentid}
    </if>
    <if test="emp.joblevelid !=null">
      and e.jobLevelId =#{emp.joblevelid}
    </if>
    <if test="emp.engageform !=null and emp.engageform!=''">
      and e.engageForm =#{emp.engageform}
    </if>
    <if test="emp.posid !=null">
      and e.posId =#{emp.posid}
    </if>
    <if test="beginDateScope !=null">
      and e.beginDate between #{beginDateScope[0]} and #{beginDateScope[1]}
    </if>
<if test="page!=null and size!=null">
  LIMIT #{page},#{size};
</if>

  </select>
  <select id="getTotal" resultType="Long">
    select count(*) from employee e
    <where>
    <if test="emp!=null">
      <if test="emp.politicid !=null">
        and e.politicId =#{emp.politicid}
      </if>
      <if test="emp.nationid !=null">
        and e.nationId =#{emp.nationid}
      </if>
      <if test="emp.departmentid !=null">
        and e.departmentId =#{emp.departmentid}
      </if>
      <if test="emp.joblevelid !=null">
        and e.jobLevelId =#{emp.joblevelid}
      </if>
      <if test="emp.engageform !=null and emp.engageform!=''">
        and e.engageForm =#{emp.engageform}
      </if>
      <if test="emp.posid !=null">
        and e.posId =#{emp.posid}
      </if>
    </if>
      <if test="beginDateScope !=null">
        and e.beginDate between #{beginDateScope[0]} and #{beginDateScope[1]}
      </if>
    </where>
  </select>
posted @ 2020-08-10 16:34  柒丶月  阅读(176)  评论(0编辑  收藏  举报