當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Springboot+Swagger
生活随笔
收集整理的這篇文章主要介紹了
Springboot+Swagger
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Swagger應用
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- swagger --><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version></dependency><!-- swagger-ui --><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version></dependency>?
@Configuration @EnableSwagger2 @EnableWebMvc public class SwaggerConfig {@Beanpublic Docket customDocket() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());}private ApiInfo apiInfo() {Contact contact = new Contact("小五", "https://swagger.io/", "xyw1005@126.com");return new ApiInfoBuilder().title("前臺API接口").description("前臺API接口").contact(contact).version("1.1.0").build();} }配置加載swagger-ui.html的路徑
@Configuration public class WebMvcConfig implements WebMvcConfigurer {@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {// TODO Auto-generated method stubregistry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");WebMvcConfigurer.super.addResourceHandlers(registry);} }?
@Controller @RequestMapping(value = "swagger") public class SwaggerTest {@ApiOperation(value = "一個測試API", notes = "第一個測試api")@ResponseBody@RequestMapping(value = "/hello", method = RequestMethod.GET)public String hello(String name) {return "hello"+name;} }?
@SpringBootApplication @ComponentScan(basePackages= {"com.wiaoong"}) public class SpringSwaggerApplication {public static void main(String[] args) {SpringApplication.run(SpringSwaggerApplication.class, args);}} http://localhost:8080/swagger-ui.html?
?
轉載于:https://www.cnblogs.com/JQKA/p/11289037.html
總結
以上是生活随笔為你收集整理的Springboot+Swagger的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 多重for循环如何提速
- 下一篇: 【python】再说装饰器与闭包的写法