外卖项目day02-员工分页查询_代码开发
This commit is contained in:
@@ -1,19 +1,25 @@
|
||||
package com.sky.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("员工分页查询数据模型")
|
||||
public class EmployeePageQueryDTO implements Serializable {
|
||||
|
||||
//员工姓名
|
||||
@ApiModelProperty("员工姓名")
|
||||
private String name;
|
||||
|
||||
//页码
|
||||
@ApiModelProperty("页码")
|
||||
private int page;
|
||||
|
||||
//每页显示记录数
|
||||
@ApiModelProperty("每页显示记录数")
|
||||
private int pageSize;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.sky.controller.admin;
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.properties.JwtProperties;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.EmployeeService;
|
||||
import com.sky.utils.JwtUtil;
|
||||
@@ -13,10 +15,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -87,4 +86,17 @@ public class EmployeeController {
|
||||
employeeService.save(employeeDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工分页查询
|
||||
* @param employeePageQueryDTO 查询数据模型
|
||||
* @return 分页查询结果
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("员工分页查询")
|
||||
public Result<PageResult> page(EmployeePageQueryDTO employeePageQueryDTO) {
|
||||
log.info("员工分页查询:{}",employeePageQueryDTO);
|
||||
PageResult pageResult = employeeService.pageQuery(employeePageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -23,4 +25,6 @@ public interface EmployeeMapper {
|
||||
@Insert("insert into employee (name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user) " +
|
||||
"values (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser})")
|
||||
void insert(Employee employee);
|
||||
|
||||
Page<Employee> pageQuery(EmployeePageQueryDTO epqyDTO);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.sky.service;
|
||||
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.result.PageResult;
|
||||
|
||||
public interface EmployeeService {
|
||||
|
||||
@@ -18,4 +20,11 @@ public interface EmployeeService {
|
||||
* @param employeeDTO
|
||||
*/
|
||||
void save(EmployeeDTO employeeDTO);
|
||||
|
||||
/**
|
||||
* 员工分页查询
|
||||
* @param employeePageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.PasswordConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.exception.AccountLockedException;
|
||||
import com.sky.exception.AccountNotFoundException;
|
||||
import com.sky.exception.PasswordErrorException;
|
||||
import com.sky.mapper.EmployeeMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.EmployeeService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -19,6 +23,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -88,4 +93,20 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
employeeMapper.insert(employee);
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工分页查询
|
||||
* @param epqyDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(EmployeePageQueryDTO epqyDTO) {
|
||||
//分页查询
|
||||
PageHelper.startPage(epqyDTO.getPage(), epqyDTO.getPageSize());
|
||||
//普通查询语句
|
||||
Page<Employee> page = employeeMapper.pageQuery(epqyDTO);
|
||||
long total = page.getTotal();
|
||||
List<Employee> records = page.getResult();
|
||||
return new PageResult(total,records);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,4 +2,13 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.EmployeeMapper">
|
||||
<select id="pageQuery" resultType="com.sky.entity.Employee">
|
||||
select * from employee
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
and name like concat('%',#{name},'%')
|
||||
</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user