使用swagger自動生成html文件
阿新 • • 發佈:2018-12-18
前後端分離,便於後臺和前臺交流。
引入依賴:
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency>
啟動類添加註解:
@SpringBootApplication
@RestController
@EnableSwagger2
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello() {
return "hello spring security";
}
}
包裝類的屬性添加註解:
package com.imooc.dto; import io.swagger.annotations.ApiModelProperty; public class UserQueryCondition { private String username; @ApiModelProperty(value="使用者年齡起始值") private int age; @ApiModelProperty(value="使用者年齡終止值") private int ageTo; private String xxx; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public int getAgeTo() { return ageTo; } public void setAgeTo(int ageTo) { this.ageTo = ageTo; } public String getXxx() { return xxx; } public void setXxx(String xxx) { this.xxx = xxx; } }
效果:
還有其它註解平時經常用的就不說了,類和方法上都有對應註解。
其它註解: