Note: This note refers to the following blog, thanks to bloggers.
1th step: Introduce related dependencies.
<dependency>
<groupId>com.mangofactory</groupId>
<ARTIFACTID>SWAGGER-SPRINGMVC </artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactid>jackson-mapper-asl</ artifactid>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
Attached: Springboot related code
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId> spring-boot-starter-parent</artifactid>
<version>1.3.1.RELEASE</version>
</parent >
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-starter-web</artifactid>
</dependency>
2nd step: Add the relevant code to the Springboot startup class
/** * Hello world!
*/@EnableSwagger @SpringBootApplication public class application {public static void main (string[] args) {
Springapplication.run (Application.class,args);
} private Springswaggerconfig Springswaggerconfig; /** * Required to Autowire springswaggerconfig */@Autowired public void Setspringswaggerconfig (SPRINGSW
Aggerconfig springswaggerconfig) {this.springswaggerconfig = Springswaggerconfig; }/** * Every Swaggerspringmvcplugin bean is picked up by the SWAGGER-MVC * framework-allowing for Multi
PLE swagger groups i.e. same Code base * Multiple Swagger resource listings. */@Bean public swaggerspringmvcplugin customimplementation () {return new Swaggerspringmvcplugin (THIS.SPR
Ingswaggerconfig). Apiinfo (Apiinfo ()). IncludePatterns (". *?"); } private Apiinfo Apiinfo () {apiinfo apiinfo = new Apiinfo ("page interface document used for Li Wei test",//APP Service
Api "subtitle", "111111111111111111111111", "121088825@qq.com", "2222222
222222222222222222222 "," 3333333333333333333333333333 ");
return apiinfo; }
}
3rd Step: Add the relevant annotations in the control class of the code
@RestController public
class Samplecontroller {
@RequestMapping (value = "/hello")
@ApiOperation (value = " Add User ", HttpMethod =" POST ", response = Userbean.class,notes =" HelloWorld ") public
UserBean Hello (@ApiParam (required = True,name = "Paramdata", value = "User information JSON data") String paramdata) {
UserBean UserBean = new UserBean ();
Userbean.setusername ("Liwei");
Userbean.setpassword ("123456");
return userBean;
}
}
Description
Where @apioperation and @apiparam are added API-related annotations, each parameter is described as follows:
@ApiOperation (value = "Interface description", HttpMethod = "Interface Request Mode", Response = "interface return parameter type", notes = "interface Release notes"; Other parameters can refer to source code;
@ApiParam (required = "parameter Required", name = "parameter name", value = "Parameter specific description"
4th Step:
Download Swaggerui on GitHub
Project (Https://github.com/swagger-api/swagger-ui), copy all content under Dist to the local project WebApp below, the resulting directory is as follows:
Modify Index.html
will be in index.html
Http://petstore.swagger.wordnik.com/v2/swagger.json
Revision changed to
Http://localhost:8080/{projectname}/api-docs
So far, all configurations complete, start your project, access
Http://localhost:8086/swagger/index.html
You can see the following page:
Company intranet Beta Project
http://192.168.12.250:8080/swagger/
Other references:
Http://www.2cto.com/kf/201502/376959.html
http://blog.csdn.net/hel12he/article/details/46547863
https://cnodejs.org/topic/555c85a6e684c4c8088a0ced
http://www.ituring.com.cn/article/131792
http://fruzenshtein.com/spring-boot-swagger-ui/
Http://jingyan.baidu.com/article/90bc8fc85ca182f653640cbf.html