swagger官網:
swagger.io/docs/
html
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swaggger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swaggger.version}</version>
</dependency>複製代碼
swagger.io/download-sw…
spring
/**
* @Author: CatalpaFlat
* @Descrition:
* @Date: Create in 11:26 2017/11/14
* @Modified BY:
*/
@EnableWebMvc
@EnableSwagger2
@Configuration
@ComponentScan(basePackages ="com.chen")
public class SwaggerConfig extends WebMvcConfigurationSupport {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.chen"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("SSM-Swagger2 APIs")
.termsOfServiceUrl("http://blog.csdn.net/dushiwodecuo")
.contact(new Contact("CatalpaFlat","http://blog.csdn.net/dushiwodecuo","1013427541@qq.com"))
.version("1.0.0")
.build();
}
}複製代碼
修改index.html中的 petstore.swagger.wordnik.com/v2/swagger.…,
例如:http://localhost:8080/api/api-docs
json
@RequestMapping
@RestController
@Api(description="測試接口")
public class TestController {
@Resource
private TestService testService;
@GetMapping(value = "get")
@ApiOperation(value = "獲取值",httpMethod = HttpMethod.GET,response = List.class,notes ="get name")
public List<Test> get(){
return testService.get();
}
@ApiOperation(value = "設置值",httpMethod = HttpMethod.GET,response = String.class,notes ="set name")
@ApiImplicitParam(value = "name",dataType = "form",required = true,defaultValue = "21378127")
@GetMapping(value = "set/{name}",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String set(@PathVariable String name){
return testService.set(name);
}
}複製代碼
瀏覽器地址欄輸入:http://localhost:8080/api/index.html
api