狂神说Swagger
学完Mybatis-Plus才发现没学过这个,补习一下吧,感觉也挺简单的。
随看随记
Swagger简介
- Swagger官网
- 其作用是提供API,解决前后端的交互不及时的问题。
- 需要在项目中引入Swagger2 和Swaggerui。
Springboot继承Swagger 输出HelloWorld
- 访问时要访问:localhost:8080/swagger-ui.html
@Configuration
@EnableSwagger2
public class swaggerConfig {
}
@RestController
public class HelloController {
@RequestMapping("/he")
public String hello(){
return "hello";
}
}
自定义Swagger信息
- 其中比较有用的就只有ApiInfo的第一个参数和第二个参数
- 分别代表API文档的名称 和Api文档的简介
@Configuration
@EnableSwagger2
public class swaggerConfig {
@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo());
}
private ApiInfo apiInfo(){
Contact contact = new Contact("paleatta","http://localhost:8080/","123456789@qq.com")