赞
踩
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- </dependency>
-
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>2.7.0</version>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>2.7.0</version>
- </dependency>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>

-
- @SpringBootApplication
- @EnableSwagger2
- public class SwaggerApp {
- public static void main(String[] args) {
- SpringApplication.run(SwaggerApp.class,args);
- }
- }
- package com.pro.config;
-
- import com.google.common.base.Predicates;
- import org.springframework.context.annotation.Bean;
- import springfox.documentation.builders.ApiInfoBuilder;
- import springfox.documentation.builders.PathSelectors;
- import springfox.documentation.service.ApiInfo;
- import springfox.documentation.service.Contact;
- import springfox.documentation.spi.DocumentationType;
- import springfox.documentation.spring.web.plugins.Docket;
-
- public class SwaConfig {
- @Bean
- public Docket webApiConfig() {
- //.groupName是组的意思
- //apiInfo 在线文档的信息
- return new Docket(DocumentationType.SWAGGER_2)
- .groupName("webApi")
- .apiInfo(webApiInfo())
- .select()
- .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
- .paths(Predicates.not(PathSelectors.regex("/error.*")))
- .build();
- }
-
- private ApiInfo webApiInfo() {
- return new ApiInfoBuilder()
- .title("网站-课程中心API文档")
- .description("本文档描述了课程中心微服务接口定义")
- .version("1.0")
- .contact(new Contact("java", "http://java.com", "111223@qq.com"))
- .build();
- }
- }

- @RestController
- public class TestController {
-
- @GetMapping("/add")
- public Object add(User user){
- return user;
- }
-
- @PostMapping("/update")
- public Object update(User user){
- return user;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。