初始化
parent
41da1dbff9
commit
00dd31c3cb
|
@ -112,5 +112,23 @@
|
|||
<artifactId>fastdfs-client</artifactId>
|
||||
<version>1.26.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Java Servlet -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<!-- knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.wzy.common.annotation;
|
||||
import com.wzy.common.config.SwaggerConfig;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import({ SwaggerConfig.class })
|
||||
public @interface EnableCustomSwagger {
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
package com.wzy.common.config;
|
||||
|
||||
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2 //开启 Swagger2
|
||||
@EnableKnife4j //开启 knife4j,可以不写
|
||||
@EnableAutoConfiguration
|
||||
@ConditionalOnProperty(name = "swagger.enable", matchIfMissing = true)
|
||||
public class SwaggerConfig {
|
||||
@Bean
|
||||
public Docket docket() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.wzy.servers"))
|
||||
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
|
||||
// 安全模式
|
||||
.securitySchemes(securitySchemes())
|
||||
// 安全上下文
|
||||
.securityContexts(securityContexts())
|
||||
.pathMapping("/");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 基本信息设置
|
||||
*/
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
// 标题
|
||||
.title("多加辣-接口文档")
|
||||
// 描述
|
||||
.description("众里寻他千百度,慕然回首那人却在灯火阑珊处")
|
||||
// 服务条款链接
|
||||
.termsOfServiceUrl("https://www.baidu.com")
|
||||
// 许可证
|
||||
.license("swagger-的使用(详细教程)")
|
||||
// 许可证链接
|
||||
.licenseUrl("https://blog.csdn.net/xhmico/article/details/125353535")
|
||||
// 联系我
|
||||
.contact(new Contact(
|
||||
"米大傻",
|
||||
"https://blog.csdn.net/xhmico?type=blog",
|
||||
"mico8080@163.com"))
|
||||
// 版本
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全模式,这里指定token通过Authorization头请求头传递
|
||||
*/
|
||||
private List<SecurityScheme> securitySchemes() {
|
||||
List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
|
||||
apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
|
||||
return apiKeyList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全上下文
|
||||
*/
|
||||
private List<SecurityContext> securityContexts() {
|
||||
List<SecurityContext> securityContexts = new ArrayList<>();
|
||||
securityContexts.add(
|
||||
SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.operationSelector(o -> o.requestMappingPattern().matches("/.*"))
|
||||
.build());
|
||||
return securityContexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认的全局鉴权策略
|
||||
*/
|
||||
private List<SecurityReference> defaultAuth() {
|
||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||
authorizationScopes[0] = authorizationScope;
|
||||
List<SecurityReference> securityReferences = new ArrayList<>();
|
||||
securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
|
||||
return securityReferences;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package com.wzy.servers;
|
||||
import com.wzy.common.annotation.EnableCustomSwagger;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@EnableCustomSwagger
|
||||
@SpringBootApplication
|
||||
public class ServersApplication {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -9,12 +9,14 @@ import com.wzy.common.domain.request.Req;
|
|||
import com.wzy.common.result.Result;
|
||||
import com.wzy.servers.service.ServersService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Log4j2
|
||||
public class ServersController {
|
||||
|
|
Loading…
Reference in New Issue