♻️ 重构代码:走向新时代,迈向更好用的Java8的日期和时间类
This commit is contained in:
1 parent
dab0aaea65
commit
71f2e69ece
16 files changed
+103
-29
No files matched your search
@@ -59,5 +59,10 @@
|
||||
<version>${servlet-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--jacksonJSR310规范-->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.common.core.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* JacksonConfig
|
||||
*
|
||||
* @author: lengleng
|
||||
* @date: 2018/7/28 12:29
|
||||
*/
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
/**
|
||||
* 处理序列化后的1.8的日期时间格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public ObjectMapper getObjectMapper() {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class,new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
javaTimeModule.addDeserializer(LocalDate.class,new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
javaTimeModule.addDeserializer(LocalTime.class,new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
||||
objectMapper.registerModule(javaTimeModule);
|
||||
return objectMapper;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.pig4cloud.pigx.common.core.config.JacksonConfig,\
|
||||
com.pig4cloud.pigx.common.core.config.RedisConfig,\
|
||||
com.pig4cloud.pigx.common.core.util.SpringContextHolder
|
||||
@@ -1 +1 @@
|
||||
provides: hutool-all, spring-cloud-starter-openfeign, feign-okhttp, fastjson, spring-boot-starter-data-redis
|
||||
provides: hutool-all, spring-cloud-starter-openfeign, feign-okhttp, fastjson, spring-boot-starter-data-redis, jackson-datatype-jsr310
|
||||
+3
-3
@@ -28,7 +28,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -58,11 +58,11 @@ public class SysDept extends Model<SysDept> {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 是否删除 -1:已删除 0:正常
|
||||
*/
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -74,11 +74,11 @@ public class SysDict extends Model<SysDict> {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
|
||||
+3
-2
@@ -25,6 +25,7 @@ import com.baomidou.mybatisplus.enums.IdType;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -60,11 +61,11 @@ public class SysLog implements Serializable {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 操作IP地址
|
||||
*/
|
||||
|
||||
+3
-3
@@ -28,7 +28,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -81,11 +81,11 @@ public class SysMenu extends Model<SysMenu> {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 0--正常 1--删除
|
||||
*/
|
||||
|
||||
+3
-3
@@ -28,7 +28,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -50,8 +50,8 @@ public class SysRole extends Model<SysRole> {
|
||||
private String roleName;
|
||||
private String roleCode;
|
||||
private String roleDesc;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 删除标识(0-正常,1-删除)
|
||||
*/
|
||||
|
||||
+3
-2
@@ -27,6 +27,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -62,11 +63,11 @@ public class SysUser implements Serializable {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 0-正常,1-删除
|
||||
*/
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.api.vo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -76,11 +76,11 @@ public class MenuVO implements Serializable {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 0--正常 1--删除
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -53,11 +53,11 @@ public class UserVO implements Serializable {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 0-正常,1-删除
|
||||
*/
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -103,7 +103,7 @@ public class DeptController {
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_dept_edit')")
|
||||
public Boolean edit(@RequestBody SysDept sysDept) {
|
||||
sysDept.setUpdateTime(new Date());
|
||||
sysDept.setUpdateTime(LocalDateTime.now());
|
||||
return sysDeptService.updateDeptById(sysDept);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -33,6 +33,7 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -98,7 +99,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
public Boolean deleteDeptById(Integer id) {
|
||||
SysDept sysDept = new SysDept();
|
||||
sysDept.setDeptId(id);
|
||||
sysDept.setUpdateTime(new Date());
|
||||
sysDept.setUpdateTime(LocalDateTime.now());
|
||||
sysDept.setDelFlag(CommonConstant.STATUS_DEL);
|
||||
this.deleteById(sysDept);
|
||||
sysDeptMapper.deleteDeptRealtion(id);
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import com.pig4cloud.pigx.admin.service.SysLogService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -45,7 +45,7 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
|
||||
SysLog sysLog = new SysLog();
|
||||
sysLog.setId(id);
|
||||
sysLog.setDelFlag(CommonConstant.STATUS_DEL);
|
||||
sysLog.setUpdateTime(new Date());
|
||||
sysLog.setUpdateTime(LocalDateTime.now());
|
||||
return updateById(sysLog);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -49,6 +49,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -168,7 +169,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
public Boolean updateUser(UserDTO userDto, String username) {
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.copyProperties(userDto, sysUser);
|
||||
sysUser.setUpdateTime(new Date());
|
||||
sysUser.setUpdateTime(LocalDateTime.now());
|
||||
this.updateById(sysUser);
|
||||
|
||||
SysUserRole condition = new SysUserRole();
|
||||
|
||||
Reference in new issue
Block a user