以下@ Api相关的是swagger2注解
@Controller
@ResponseBody
@RequestMapping("/user")
@Api(value = "提供用户管理相关的api",tags = "用户管理接口")//类说明
public class UserController {
@Resource
private UserService userService;
@ApiOperation("用户注册接口")//接口说明
@RequestMapping(value = "/register",method = RequestMethod.POST)
public User registerUser(User user) {
boolean res = userService.register(user);
if (res){
return user;
}
return null;
}
@ApiOperation("用户登录接口")
//参数说明
@ApiImplicitParams({
@ApiImplicitParam(dataType = "string",name = "username",value = "用户名",required = true),
@ApiImplicitParam(dataType = "string",name = "password",value = "密码",defaultValue = "123456",required = false)
})
@RequestMapping(value = "/login",method = RequestMethod.GET)
public ResultVO login(@RequestParam("username") String username,
@RequestParam(value = "password",defaultValue = "123456") String pwd) {
return userService.checkLogin(username,pwd);
}
}
当参数或返回值为对象,在具体的类中说明如下:
@ApiModel(value = "ResultVO-响应对象",description = "封装了接口返回数据")
public class ResultVO {
@ApiModelProperty(value = "状态码",dataType = "int")
private Integer code;
@ApiModelProperty(value = "信息",dataType = "string")
private String msg;
@ApiModelProperty(value = "响应内容")
private Object object;
}
网友评论