原创文章,转载请注明原文章地址,谢谢!
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
Docket docket = null;
docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("百度-微服务")
.description("百度一下,你就知道")
.termsOfServiceUrl("www.baidu.com")
.contact("微服务小组")
.version("1.0")
.build();
}
}
@Api(value = "Demo", description = "Demo接口")
@RestController
@RequestMapping("/demo")
public class SwaggerDemoController {
@ApiOperation(value = "小样", notes = "小样", response = Object.class)
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "id", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "content", value = "内容", dataType = "string", paramType = "query")
})
@RequestMapping(value = "/hello", method = {RequestMethod.GET, RequestMethod.POST})
public String hello(@RequestParam("id") String id, @RequestParam(name = "content", required = false) String content) {
return id + content;
}
}
博客内容仅供自已学习以及学习过程的记录,如有侵权,请联系我删除,谢谢!
网友评论