Swagger2文档生成器
Swagger2配置文件:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
private ApiInfo apiInfo(){
return new ApiInfoBuilder().title("增删改的restful风格")
.description("中公教育优就业")
.termsOfServiceUrl("http://ujiuye")
.contact("sunny")
.version("1.0")
.build();
}
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.offcn.demo01.web"))
.paths(PathSelectors.any())
.build();
}
}
web层的接口方法加注解:
@ApiOperation(value="更新指定name用户", notes = "根据name修改用户信息")
@ApiImplicitParams({
@ApiImplicitParam(name="name",value = "用户姓名",required = true,dataType = "String"),
@ApiImplicitParam(name="userBody",value="用户的详细信息",required = true,dataType = "UserBody")
})
@PutMapping("/{name}")
public void put(UserBody userBody,@PathVariable("name") String name){
for (UserBody body : list) {
if(body.getName() .equals(name)){
body.setDate(userBody.getDate());
}
}
}
swagger2所需的依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>