Spring MVC 4 Swager 2を配置
8526 ワード
io.springfox
springfox-swagger2
2.7.0
io.springfox
springfox-swagger-ui
2.7.0
com.fasterxml.jackson.core
jackson-core
2.8.7
com.fasterxml.jackson.core
jackson-databind
2.8.7
com.fasterxml.jackson.core
jackson-annotations
2.8.7
text/plain;charset=UTF-8
text/html;charset=UTF-8
application/json;charset=UTF-8
application/x-www-form-urlencoded;charset=UTF-8
application/json;charset=UTF-8
@Configuration
@EnableSwagger2
public class Swagger2Config{
public Swagger2Config() {
System.out.println("Swagger2Config.Swagger2Config");
}
@Bean
public Docket createRestApi() {
System.out.println("Swagger2Config.createRestApi");
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.ecs.swagger2.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(" API ")
.description(" API ")
.termsOfServiceUrl("https://blog.csdn.net/mxj588love")
.version("1.0")
.build();
}
}
@Api(tags = " ")
@RestController
@RequestMapping
public class Swagger2Controller {
@ApiOperation(value = " ", notes = " ")
@ApiImplicitParam(name = "id", value = " ID", required = true, dataType = "String", paramType = "path")
@GetMapping("/getServerInfo")
public String getServerInfo(HttpServletRequest request, ModelMap modelMap) {
modelMap.addAttribute("RemoteAddr", request.getRemoteAddr());
modelMap.addAttribute("RemoteHost", request.getRemoteHost());
modelMap.addAttribute("RemotePort", request.getRemotePort());
modelMap.addAttribute("RemoteUser", request.getRemoteUser());
return modelMap.toString();
}
@ApiOperation(" ")
@GetMapping("/getUserList")
@ResponseBody
public List getEquipTypeInfo() {
List list = Arrays.asList("zhangsan", "lisi", "wangwu");
return list;
}
@ApiOperation(value = " ", notes = " ")
@ApiImplicitParams({
@ApiImplicitParam(name = "name", value = " ", dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "address", value = " ", dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "city", value = " ", dataType = "String", paramType = "query")
})
@PostMapping("/putUser")
@ResponseBody
public String putUser(ModelMap modelMap) {
modelMap.addAttribute("title", " ");
modelMap.addAttribute("success", true);
return modelMap.toString();
}
}
NEW Swagger UI