@@ -10,7 +10,7 @@ swagger用于定义API文档。
1010* 传统的输入URL的测试方式对于post请求的传参比较麻烦(当然,可以使用postman这样的浏览器插件)
1111* spring-boot与swagger的集成简单的一逼
1212
13- Maven
13+ Maven项目
1414
1515``` Xml
1616 <dependency >
2525 </dependency >
2626```
2727
28- Gradle
28+ Gradle项目
2929
3030 compile ("io.springfox:springfox-swagger2:2.2.2")
3131 compile ("io.springfox:springfox-swagger-ui:2.2.2")
@@ -52,6 +52,8 @@ object StartSpringBootApplication extends App {
5252
5353在controller层加入swagger api注解
5454
55+ Scala 模式
56+
5557```Java
5658
5759@ComponentScan
@@ -70,6 +72,34 @@ class UserController @Autowired()(private val userService : UserService){
7072
7173}
7274```
75+
76+ Java 模式
77+
78+ ```Java
79+ @RestController
80+ @RequestMapping (" /user" )
81+ @Api (" userController相关api" )
82+ public class UserController {
83+
84+ @Autowired
85+ private UserService userService;
86+
87+ @ApiOperation (" 获取用户信息" )
88+ @ApiImplicitParams ({
89+ @ApiImplicitParam (paramType = " header" ,name = " username" ,dataType = " String" ,required = true ,value = " 用户的姓名" ,defaultValue = " zhaojigang" ),
90+ @ApiImplicitParam (paramType = " query" ,name = " password" ,dataType = " String" ,required = true ,value = " 用户的密码" ,defaultValue = " wangna" )
91+ })
92+ @ApiResponses ({
93+ @ApiResponse (code = 400 ,message = " 请求参数没填好" ),
94+ @ApiResponse (code = 404 ,message = " 请求路径没有或页面跳转路径不对" )
95+ })
96+ @RequestMapping (value = " /getUser" ,method = RequestMethod . GET )
97+ public User getUser (@RequestHeader (" username" ) String username , @RequestParam (" password" ) String password ) {
98+ return userService. getUser(username,password);
99+ }
100+ }
101+ ```
102+
73103说明:
74104
75105* @Api :用在类上,说明该类的作用
0 commit comments