初始代码
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package com.sky.config;
|
||||
|
||||
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
||||
import com.sky.json.JacksonObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
@@ -15,6 +19,8 @@ import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 配置类,注册web层相关组件
|
||||
*/
|
||||
@@ -70,4 +76,19 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展SpringMVC框架的消息转换器
|
||||
* @param converters
|
||||
*/
|
||||
@Override
|
||||
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
log.info("扩展消息转换器...");
|
||||
//创建一个消息转换器对象
|
||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||
//为消息转换器设置一个对象转换器,对象转换器可以将Java对象序列化为json数据
|
||||
converter.setObjectMapper(new JacksonObjectMapper());
|
||||
//添加消息转换器至容器中
|
||||
converters.add(0,converter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -77,6 +76,11 @@ public class EmployeeController {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增员工
|
||||
* @param employeeDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增员工")
|
||||
public Result save(@RequestBody EmployeeDTO employeeDTO) {
|
||||
@@ -85,4 +89,16 @@ public class EmployeeController {
|
||||
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,11 @@ public interface EmployeeMapper {
|
||||
@Insert("insert into employee (name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user) " +
|
||||
"values (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
|
||||
void insert(Employee employee);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param employeePageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
Page<Employee> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
||||
}
|
||||
|
||||
@@ -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 org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -18,6 +22,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
@@ -86,4 +91,22 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
employeeMapper.insert(employee);
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工分页查询
|
||||
* @param employeePageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO) {
|
||||
//分页查询
|
||||
PageHelper.startPage(employeePageQueryDTO.getPage(),employeePageQueryDTO.getPageSize());
|
||||
|
||||
Page<Employee> page = employeeMapper.pageQuery(employeePageQueryDTO);
|
||||
|
||||
long total = page.getTotal();
|
||||
List<Employee> records = page.getResult();
|
||||
|
||||
return new PageResult(total,records);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user