使用Knife4j加强实现的Swagger生成API文档
This commit is contained in:
parent
d75037fe93
commit
529a0a755c
5
pom.xml
5
pom.xml
@ -37,6 +37,11 @@
|
|||||||
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
|
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
|
||||||
<version>4.1.1</version>
|
<version>4.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.3</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
package cn.czyx007.reggie.config;
|
package cn.czyx007.reggie.config;
|
||||||
|
|
||||||
import cn.czyx007.reggie.common.JacksonObjectMapper;
|
import cn.czyx007.reggie.common.JacksonObjectMapper;
|
||||||
|
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||||
|
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.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
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;
|
||||||
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -14,13 +23,36 @@ import java.util.List;
|
|||||||
* @createTime : 2022/12/20 - 19:54
|
* @createTime : 2022/12/20 - 19:54
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@EnableSwagger2
|
||||||
|
@EnableKnife4j
|
||||||
public class WebMvcConfig extends WebMvcConfigurationSupport {
|
public class WebMvcConfig extends WebMvcConfigurationSupport {
|
||||||
|
private ApiInfo apiInfo(){
|
||||||
|
return new ApiInfoBuilder()
|
||||||
|
.title("瑞吉外卖")
|
||||||
|
.version("1.0")
|
||||||
|
.description("瑞吉外卖接口文档")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Docket createRestApi(){
|
||||||
|
//文档类型
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.apiInfo(apiInfo())
|
||||||
|
.select()
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("cn.czyx007.reggie.controller"))
|
||||||
|
.paths(PathSelectors.any())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置静态资源映射
|
* 设置静态资源映射
|
||||||
* @param registry
|
* @param registry
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/static/backend/");
|
registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/static/backend/");
|
||||||
registry.addResourceHandler("/front/**").addResourceLocations("classpath:/static/front/");
|
registry.addResourceHandler("/front/**").addResourceLocations("classpath:/static/front/");
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package cn.czyx007.reggie.filter;
|
package cn.czyx007.reggie.filter;
|
||||||
|
|
||||||
import cn.czyx007.reggie.bean.Employee;
|
|
||||||
import cn.czyx007.reggie.common.BaseContext;
|
import cn.czyx007.reggie.common.BaseContext;
|
||||||
import cn.czyx007.reggie.common.R;
|
import cn.czyx007.reggie.common.R;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import org.springframework.boot.json.JacksonJsonParser;
|
|
||||||
import org.springframework.util.AntPathMatcher;
|
import org.springframework.util.AntPathMatcher;
|
||||||
|
|
||||||
import javax.servlet.*;
|
import javax.servlet.*;
|
||||||
@ -21,8 +19,8 @@ import java.io.IOException;
|
|||||||
@WebFilter(filterName = "loginCheckFilter", urlPatterns = "/*")
|
@WebFilter(filterName = "loginCheckFilter", urlPatterns = "/*")
|
||||||
public class LoginCheckFilter implements Filter {
|
public class LoginCheckFilter implements Filter {
|
||||||
private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();
|
private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();
|
||||||
public static final String[] urls = {"/employee/login", "/employee/logout", "/backend/**", "/front/**",
|
private static final String[] urls = {"/employee/login", "/employee/logout", "/backend/**", "/front/**",
|
||||||
"/user/sendMsg", "/user/login"};
|
"/user/sendMsg", "/user/login", "/doc.html", "/webjars/**", "/swagger-resources", "/v2/api-docs"};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user