Skip to content

Commit

Permalink
refactor: 适配 Jackson、API 文档(Knife4j:Spring Doc)自动配置
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Nov 21, 2023
1 parent ec1daaf commit a86f3a5
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 168 deletions.
16 changes: 8 additions & 8 deletions continew-admin-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
<description>公共模块(存放公共工具类,公共配置等)</description>

<dependencies>
<!-- ContiNew Starter 核心依赖 -->
<!-- ContiNew Starter API 文档依赖 -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-core</artifactId>
<artifactId>continew-starter-api-doc</artifactId>
</dependency>

<!-- ContiNew Starter Jackson 依赖 -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-json-jackson</artifactId>
</dependency>

<!-- ################ Spring Boot 相关 ################ -->
Expand Down Expand Up @@ -108,12 +114,6 @@
<artifactId>mica-ip2region</artifactId>
</dependency>

<!-- Knife4j(前身是 swagger-bootstrap-ui,集 Swagger2 和 OpenAPI3 为一体的增强解决方案) -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
</dependency>

<!-- Redisson(不仅仅是一个 Redis Java 客户端) -->
<dependency>
<groupId>org.redisson</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
.setCachePeriod(0);
registry.addResourceHandler(localStorageProperties.getAvatarPattern()).addResourceLocations(avatarUtl)
.setCachePeriod(0);
registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/");
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/")
.setCacheControl(CacheControl.maxAge(5, TimeUnit.HOURS).cachePublic());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,6 @@
@Configuration
public class JacksonConfiguration {

/**
* 针对时间类型:LocalDateTime、LocalDate、LocalTime 的序列化和反序列化
*/
@Bean
public Jackson2ObjectMapperBuilderCustomizer customizer() {
return builder -> {
JavaTimeModule javaTimeModule = new JavaTimeModule();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN);
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(dateTimeFormatter));
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(dateTimeFormatter));

DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN);
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(dateFormatter));
javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(dateFormatter));

DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN);
javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(timeFormatter));
javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(timeFormatter));
builder.timeZone(TimeZone.getDefault());
builder.modules(javaTimeModule);
log.info(">>>初始化 Jackson 序列化配置<<<");
};
}

/**
* 针对枚举基类 BaseEnum 的序列化和反序列化
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,55 +36,7 @@
*/
@Data
@Component
@ConfigurationProperties(prefix = "project")
public class ProjectProperties {

/**
* 名称
*/
private String name;

/**
* 应用名称
*/
private String appName;

/**
* 版本
*/
private String version;

/**
* 描述
*/
private String description;

/**
* URL
*/
private String url;

/**
* 基本包
*/
private String basePackage;

/**
* 作者信息
*/
@NestedConfigurationProperty
private Contact author;

/**
* 许可协议信息
*/
@NestedConfigurationProperty
private License license;

/**
* 是否为生产环境
*/
private boolean production = false;
public class ProjectProperties extends top.charles7c.continew.starter.core.autoconfigure.ProjectProperties {

/**
* 是否本地解析 IP 归属地
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ project:
# 基本包
basePackage: top.charles7c.cnadmin
## 作者信息配置
author:
contact:
name: Charles7c
email: charles7c@126.com
url: https://blog.charles7c.top/about/me
Expand Down
10 changes: 0 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<justauth.version>1.16.5</justauth.version>
<easyexcel.version>3.3.2</easyexcel.version>
<ip2region.version>3.1.5.1</ip2region.version>
<knife4j.version>4.3.0</knife4j.version>
<redisson.version>3.24.3</redisson.version>
<easy-captcha.version>1.6.2</easy-captcha.version>
<hutool.version>5.8.22</hutool.version>
Expand Down Expand Up @@ -139,15 +138,6 @@
<version>${ip2region.version}</version>
</dependency>

<!-- Knife4j(前身是 swagger-bootstrap-ui,集 Swagger2 和 OpenAPI3 为一体的增强解决方案) -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-dependencies</artifactId>
<version>${knife4j.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- Redisson(不仅仅是一个 Redis Java 客户端) -->
<dependency>
<groupId>org.redisson</groupId>
Expand Down

0 comments on commit a86f3a5

Please sign in to comment.