Skip to content

Commit 93beace

Browse files
committed
springboot-swagger
1 parent 2156074 commit 93beace

File tree

21 files changed

+105
-654
lines changed

21 files changed

+105
-654
lines changed

springboot-web-swagger/pom.xml

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -31,72 +31,6 @@
3131
</exclusions>
3232
</dependency>
3333

34-
<dependency>
35-
<groupId>org.springframework.boot</groupId>
36-
<artifactId>spring-boot-starter-test</artifactId>
37-
<scope>test</scope>
38-
</dependency>
39-
40-
<!-- thymeleaf 模版-->
41-
<dependency>
42-
<groupId>org.springframework.boot</groupId>
43-
<artifactId>spring-boot-starter-thymeleaf</artifactId>
44-
</dependency>
45-
46-
<dependency>
47-
<groupId>org.springframework.boot</groupId>
48-
<artifactId>spring-boot-starter-aop</artifactId>
49-
</dependency>
50-
51-
<!-- 阿里 fastjson -->
52-
<dependency>
53-
<groupId>com.alibaba</groupId>
54-
<artifactId>fastjson</artifactId>
55-
<version>1.2.47</version>
56-
</dependency>
57-
58-
59-
<!-- Lombok 工具 -->
60-
<dependency>
61-
<groupId>org.projectlombok</groupId>
62-
<artifactId>lombok</artifactId>
63-
<optional>true</optional>
64-
</dependency>
65-
66-
<!-- 导入配置文件处理器,在配置springboot相关文件时候会有提示 -->
67-
<dependency>
68-
<groupId>org.springframework.boot</groupId>
69-
<artifactId>spring-boot-configuration-processor</artifactId>
70-
<optional>true</optional>
71-
</dependency>
72-
73-
<!-- 单元测试 -->
74-
<dependency>
75-
<groupId>org.junit.jupiter</groupId>
76-
<artifactId>junit-jupiter-api</artifactId>
77-
<version>RELEASE</version>
78-
<scope>compile</scope>
79-
</dependency>
80-
81-
<!-- Web Jars 静态资源文件 -->
82-
<dependency>
83-
<groupId>org.webjars</groupId>
84-
<artifactId>bootstrap</artifactId>
85-
<version>4.1.3</version>
86-
</dependency>
87-
88-
<!-- 数据库访问 JPA-->
89-
<dependency>
90-
<groupId>org.springframework.boot</groupId>
91-
<artifactId>spring-boot-starter-data-jpa</artifactId>
92-
</dependency>
93-
94-
<!--添加数据库链接 -->
95-
<dependency>
96-
<groupId>mysql</groupId>
97-
<artifactId>mysql-connector-java</artifactId>
98-
</dependency>
99-
10034
<!-- 引入swagger2的依赖-->
10135
<dependency>
10236
<groupId>io.springfox</groupId>
@@ -116,13 +50,22 @@
11650
<version>2.5.4</version>
11751
</dependency>
11852

53+
<!-- Lombok 工具 -->
11954
<dependency>
120-
<groupId>com.fasterxml</groupId>
121-
<artifactId>classmate</artifactId>
122-
<version>1.2.0</version>
55+
<groupId>org.projectlombok</groupId>
56+
<artifactId>lombok</artifactId>
57+
<optional>true</optional>
58+
</dependency>
59+
60+
<!-- 导入配置文件处理器,在配置springboot相关文件时候会有提示 -->
61+
<dependency>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-configuration-processor</artifactId>
64+
<optional>true</optional>
12365
</dependency>
12466

12567
</dependencies>
68+
12669
<build>
12770
<plugins>
12871
<plugin>

springboot-web-swagger/src/main/java/net/codingme/boot/BootApplication.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* Spring Boot 启动类
99
* </p>
1010
*/
11-
1211
@SpringBootApplication
1312
public class BootApplication {
1413

springboot-web-swagger/src/main/java/net/codingme/boot/config/ConverterDate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* 时间转换器
1313
*
1414
* @Author niujinpeng
15-
* @Date 2019/1/11 15:18
15+
* @Date 2019/11/19 23:17
1616
*/
1717
public class ConverterDate implements Converter<String, Date> {
1818

springboot-web-swagger/src/main/java/net/codingme/boot/config/LogAspect.java

Lines changed: 0 additions & 97 deletions
This file was deleted.

springboot-web-swagger/src/main/java/net/codingme/boot/config/LogHandlerInterceptor.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

springboot-web-swagger/src/main/java/net/codingme/boot/config/SwaggerConfig.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import springfox.documentation.builders.RequestHandlerSelectors;
88
import springfox.documentation.service.ApiInfo;
99
import springfox.documentation.spi.DocumentationType;
10-
import springfox.documentation.spring.web.ObjectMapperConfigurer;
1110
import springfox.documentation.spring.web.plugins.Docket;
1211
import springfox.documentation.swagger2.annotations.EnableSwagger2;
1312

1413
/**
1514
* <p>
15+
* Springfox-swagger2 配置
1616
*
1717
* @Author niujinpeng
18-
* @Date 2019/1/11 17:44
18+
* @Date 2019/11/19 23:17
1919
*/
2020
@Configuration
2121
@EnableSwagger2
@@ -31,13 +31,12 @@ public Docket createRestApi() {
3131
.build();
3232
}
3333

34-
3534
private ApiInfo apiInfo() {
3635
return new ApiInfoBuilder()
37-
.title("Spring Boot 使用 Swagger2构建RESTFul APIs")
38-
.description("springboot swagger2 test...")
36+
.title("未读代码 API")
37+
.description("公众号:未读代码(weidudaima) springboot-swagger2 在线借口文档")
3938
.termsOfServiceUrl("https://www.codingme.net")
40-
.contact("niumoo")
39+
.contact("达西呀")
4140
.version("1.0")
4241
.build();
4342
}

springboot-web-swagger/src/main/java/net/codingme/boot/config/WebMvcConfig.java

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,26 @@
11
package net.codingme.boot.config;
22

3-
4-
import com.alibaba.fastjson.serializer.SerializerFeature;
5-
import com.alibaba.fastjson.support.config.FastJsonConfig;
6-
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
73
import org.springframework.context.annotation.Configuration;
84
import org.springframework.format.FormatterRegistry;
9-
import org.springframework.http.MediaType;
10-
import org.springframework.http.converter.HttpMessageConverter;
11-
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
125
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
136
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
147

15-
import java.util.ArrayList;
16-
import java.util.List;
17-
188
/**
199
* <p>
20-
* 1.使用FastJSON
2110
* 2.配置时间格式化
22-
* 3.解决中文乱码
2311
* 4.添加自定义拦截器
2412
* 5.时间转换器
2513
*
2614
* @Author niujinpeng
27-
* @Date 2018/12/13 15:35
15+
* @Date 2019/11/19 23:17
2816
*/
2917
@Configuration
3018
public class WebMvcConfig implements WebMvcConfigurer {
3119

32-
/**
33-
* 自定义JSON转换器
34-
*
35-
* @param converters
36-
*/
37-
@Override
38-
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
39-
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
40-
FastJsonConfig fastJsonConfig = new FastJsonConfig();
41-
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
42-
//日期格式化
43-
fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
44-
//处理中文乱码问题
45-
List<MediaType> fastMediaTypes = new ArrayList<>();
46-
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
47-
48-
converter.setSupportedMediaTypes(fastMediaTypes);
49-
converter.setFastJsonConfig(fastJsonConfig);
50-
converters.add(converter);
51-
}
52-
53-
/**
54-
* 添加自定义拦截器
55-
* .addPathPatterns("/**") 拦截的请求路径
56-
* .excludePathPatterns("/user"); 排除的请求路径
57-
*
58-
* @param registry
59-
*/
60-
@Override
61-
public void addInterceptors(InterceptorRegistry registry) {
62-
registry.addInterceptor(new LogHandlerInterceptor())
63-
.addPathPatterns("/**")
64-
.excludePathPatterns("/user");
65-
}
66-
6720

6821
@Override
6922
public void addResourceHandlers(ResourceHandlerRegistry registry) {
70-
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
23+
//registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
7124
}
7225

7326
/**

0 commit comments

Comments
 (0)