1.代码
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
@RestController
@Api(tags = "用户管理相关接口")
@RequestMapping("/user")
public class A {
@RequestMapping(value = "/",method = RequestMethod.POST)
@ApiOperation(value = "添加用户的接口",notes = "接口说明")
@ApiImplicitParams({
@ApiImplicitParam(name = "username" ,value = "用户名",defaultValue = "1",dataType = "String"),
@ApiImplicitParam(name = "address",value = "用户地址",defaultValue = "深圳",required = true)
})
public RespBean addUser(String username, @RequestParam(required = true) String address)
{
return new RespBean(username,address);
}
}
2.解释
在控制类中
@Api(tags = “”) 是对控制类的注解
@ApiOperation(value = “”,notes = “”) 是对方法的注解 value代表该方法的作用,notes代表该方法的具体描述
@ApiImplicitParams({ }) 表示方法的一组参数
@ApiImplicitParam(name = “” ,value = “”,defaultValue = “”,dataType = “”,required = true),表示一个参数,name表示参数名,value是参数的描述,dataType是参数的类型,defaultValue 是参数的默认值,required是参数是否必须