swagger为什么要用3,不用2呢?原因很简单,对于手残的我来讲,3更简单,几乎不费吹灰之力就可以完成配置和使用。
- 添加依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
- 启动类添加开关
@SpringBootApplication
@EnableOpenApi
public class LoginApplication {
public static void main(String[] args) {
SpringApplication.run(LoginApplication.class, args);
}
}
- controller添加api说明
@RequestMapping(value = "login/{username}",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "输入用户名,获取登陆t-passport3的common_session_id1")
//@ApiImplicitParam(name = "username",value = "登陆用户名")
@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", dataType = "MessageParam", name = "username", value = "用户名", required = true,defaultValue = "cpu") })
@ApiResponse(code = 200, message ="成功" , response = Result.class)
public StringBuffer login(@PathVariable("username") String username){
return httpRequest.sendPostLogin(username);
}
- 访问
http://localhost:8080/swagger-ui/index.html