//----------------------------Graddle依赖-----------------------------------------
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.4.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.4.0'
//-----------------------------Swagger配置---------------------------------------
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("web.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("restful api")
.description("接口描述")
.termsOfServiceUrl("http://localhost:9191/small")
.contact(new Contact("chawintyan","http://localhost:9191/small/home","chawintyan@aliyun.com"))
.version("1.0")
.build();
}
}
//-----------------------------Controller配置---------------------------------------
@ApiOperation(value = "获取用户列表", notes = "用来获取全部用户信息")
@ApiImplicitParam(name = "userName", value = "用户名称", required = true, dataType = "String")
@RequestMapping(value = "queryUsers", method = RequestMethod.GET)
public List<User> queryUsers(String userName){
LOG.info("【请求用户名.{}】", userName);
return loginService.queryUsers(userName);
}
访问地址 http://localhost:9191/small/swagger-ui.html