消息转换器
This commit is contained in:
parent
3a1faa5ac2
commit
13bd3dc21e
|
@ -1,5 +1,6 @@
|
||||||
package com.sky.dto;
|
package com.sky.dto;
|
||||||
|
|
||||||
|
import com.sky.entity.Employee;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -15,5 +16,4 @@ public class EmployeePageQueryDTO implements Serializable {
|
||||||
|
|
||||||
//每页显示记录数
|
//每页显示记录数
|
||||||
private int pageSize;
|
private int pageSize;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.sky.entity;
|
package com.sky.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -29,7 +30,7 @@ public class Employee implements Serializable {
|
||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy年MM月dd日 HH:mm:ss")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
package com.sky.config;
|
package com.sky.config;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.pattern.MessageConverter;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
||||||
|
import com.sky.json.JacksonObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
@ -15,6 +20,9 @@ import springfox.documentation.service.ApiInfo;
|
||||||
import springfox.documentation.spi.DocumentationType;
|
import springfox.documentation.spi.DocumentationType;
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置类,注册web层相关组件
|
* 配置类,注册web层相关组件
|
||||||
*/
|
*/
|
||||||
|
@ -22,13 +30,13 @@ import springfox.documentation.spring.web.plugins.Docket;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册自定义拦截器
|
* 注册自定义拦截器
|
||||||
*
|
*
|
||||||
* @param registry
|
* @param registry InterceptorRegistry
|
||||||
*/
|
*/
|
||||||
protected void addInterceptors(InterceptorRegistry registry) {
|
protected void addInterceptors(InterceptorRegistry registry) {
|
||||||
log.info("开始注册自定义拦截器...");
|
log.info("开始注册自定义拦截器...");
|
||||||
|
@ -39,7 +47,8 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过knife4j生成接口文档
|
* 通过knife4j生成接口文档
|
||||||
* @return
|
*
|
||||||
|
* @return Docket
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public Docket docket() {
|
public Docket docket() {
|
||||||
|
@ -59,10 +68,25 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置静态资源映射
|
* 设置静态资源映射
|
||||||
* @param registry
|
*
|
||||||
|
* @param registry ResourceHandlerRegistry
|
||||||
*/
|
*/
|
||||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展Spring MVC框架转换器
|
||||||
|
*
|
||||||
|
* @param converters List<HttpMessageConverter<?>>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
|
super.extendMessageConverters(converters);
|
||||||
|
log.info("扩展消息转换器...");
|
||||||
|
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||||
|
converter.setObjectMapper(new JacksonObjectMapper());
|
||||||
|
converters.add(0,converter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,10 @@ import com.sky.constant.PasswordConstant;
|
||||||
import com.sky.constant.StatusConstant;
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.dto.EmployeeDTO;
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import com.sky.properties.JwtProperties;
|
import com.sky.properties.JwtProperties;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.service.EmployeeService;
|
import com.sky.service.EmployeeService;
|
||||||
import com.sky.utils.JwtUtil;
|
import com.sky.utils.JwtUtil;
|
||||||
|
@ -18,10 +20,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -92,9 +91,22 @@ public class EmployeeController {
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "新增员工")
|
@Operation(summary = "新增员工")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public Result save(@RequestBody EmployeeDTO employeeDTO) {
|
public Result<String> save(@RequestBody EmployeeDTO employeeDTO) {
|
||||||
log.info("新增员工:{}", employeeDTO);
|
log.info("新增员工:{}", employeeDTO);
|
||||||
employeeService.insert(employeeDTO);
|
employeeService.insert(employeeDTO);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工分页查询
|
||||||
|
*
|
||||||
|
* @return Result<PageResult>
|
||||||
|
*/
|
||||||
|
@Operation(summary = "员工分页查询")
|
||||||
|
@GetMapping("/page")
|
||||||
|
public Result<PageResult> pageResultResult(EmployeePageQueryDTO employeePageQueryDTO) {
|
||||||
|
log.info("员工查找,参数为:{}", employeeService);
|
||||||
|
PageResult pageResult = employeeService.pageQuery(employeePageQueryDTO);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import org.apache.ibatis.annotations.Insert;
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
@ -21,4 +23,11 @@ public interface EmployeeMapper {
|
||||||
* @param employee 员工
|
* @param employee 员工
|
||||||
*/
|
*/
|
||||||
void insert(Employee employee);
|
void insert(Employee employee);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工分页查询
|
||||||
|
* @param employeePageQueryDTO EmployeePageQueryDTO
|
||||||
|
* @return Page<Employee>
|
||||||
|
*/
|
||||||
|
Page<Employee> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.sky.service;
|
||||||
|
|
||||||
import com.sky.dto.EmployeeDTO;
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
|
||||||
public interface EmployeeService {
|
public interface EmployeeService {
|
||||||
|
|
||||||
|
@ -18,4 +20,11 @@ public interface EmployeeService {
|
||||||
* @param employeeDTO 请求新增员工参数
|
* @param employeeDTO 请求新增员工参数
|
||||||
*/
|
*/
|
||||||
void insert(EmployeeDTO employeeDTO);
|
void insert(EmployeeDTO employeeDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工分页查询
|
||||||
|
* @param employeeLoginDTO EmployeeService
|
||||||
|
* @return PageResult
|
||||||
|
*/
|
||||||
|
PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
package com.sky.service.impl;
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.sky.constant.MessageConstant;
|
import com.sky.constant.MessageConstant;
|
||||||
import com.sky.constant.PasswordConstant;
|
import com.sky.constant.PasswordConstant;
|
||||||
import com.sky.constant.StatusConstant;
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.context.BaseContext;
|
import com.sky.context.BaseContext;
|
||||||
import com.sky.dto.EmployeeDTO;
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import com.sky.exception.AccountLockedException;
|
import com.sky.exception.AccountLockedException;
|
||||||
import com.sky.exception.AccountNotFoundException;
|
import com.sky.exception.AccountNotFoundException;
|
||||||
import com.sky.exception.PasswordErrorException;
|
import com.sky.exception.PasswordErrorException;
|
||||||
import com.sky.mapper.EmployeeMapper;
|
import com.sky.mapper.EmployeeMapper;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
import com.sky.service.EmployeeService;
|
import com.sky.service.EmployeeService;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -21,6 +25,7 @@ import javax.annotation.Resource;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EmployeeServiceImpl implements EmployeeService {
|
public class EmployeeServiceImpl implements EmployeeService {
|
||||||
|
@ -66,10 +71,11 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入员工数据
|
* 插入员工数据
|
||||||
|
*
|
||||||
* @param employeeDTO EmployeeDTO
|
* @param employeeDTO EmployeeDTO
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void insert(EmployeeDTO employeeDTO) {
|
public void insert(EmployeeDTO employeeDTO) {
|
||||||
Employee employee = new Employee();
|
Employee employee = new Employee();
|
||||||
// 对象属性拷贝
|
// 对象属性拷贝
|
||||||
BeanUtils.copyProperties(employeeDTO, employee);
|
BeanUtils.copyProperties(employeeDTO, employee);
|
||||||
|
@ -90,4 +96,20 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||||
employeeMapper.insert(employee);
|
employeeMapper.insert(employee);
|
||||||
BaseContext.removeCurrentId();
|
BaseContext.removeCurrentId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工分页查询
|
||||||
|
*
|
||||||
|
* @param employeePageQueryDTO EmployeeService
|
||||||
|
* @return PageResult
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO) {
|
||||||
|
PageHelper.startPage(employeePageQueryDTO.getPage(), employeePageQueryDTO.getPageSize());
|
||||||
|
Page<Employee> page = employeeMapper.pageQuery(employeePageQueryDTO);
|
||||||
|
long total = page.getTotal();
|
||||||
|
List<Employee> result = page.getResult();
|
||||||
|
|
||||||
|
return new PageResult(total, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,22 @@
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.sky.mapper.EmployeeMapper">
|
<mapper namespace="com.sky.mapper.EmployeeMapper">
|
||||||
|
|
||||||
|
<!-- 新增员工 -->
|
||||||
<insert id="insert">
|
<insert id="insert">
|
||||||
insert into employee (name, username, password, phone, sex, id, id_number, status, create_time, update_time,
|
insert into employee (name, username, password, phone, sex, id, id_number, status, create_time, update_time,
|
||||||
create_user, update_user)
|
create_user, update_user)
|
||||||
values (#{name}, #{username}, #{password}, #{phone}, #{sex}, #{id}, #{idNumber}, #{status}, #{createTime},
|
values (#{name}, #{username}, #{password}, #{phone}, #{sex}, #{id}, #{idNumber}, #{status}, #{createTime},
|
||||||
#{updateTime}, #{createUser}, #{updateUser});
|
#{updateTime}, #{createUser}, #{updateUser});
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<!-- 员工分页查询 -->
|
||||||
|
<select id="pageQuery" resultType="com.sky.entity.Employee">
|
||||||
|
select * from employee
|
||||||
|
<where>
|
||||||
|
<if test="name!='' and name!=null">
|
||||||
|
and name like concat('%',#{name},'%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by create_time desc
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue