swagger基本注解

与使用Swagger核心注释注释模型类以提供其他元数据相同,可以注释控制器及其方法和方法参数。

@Api描述了整个控制器
@ApiOperation用于方法级别的描述
@ApiParam用于方法参数

@RestController
@RequestMapping("/v2/persons/")
@Api(description = “Set of endpoints for Creating, Retrieving, Updating and Deleting of Persons.”)
public class PersonController {

private PersonService personService;

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
@ApiOperation("Returns list of all Persons in the system.")
public List getAllPersons() {
    return personService.getAllPersons();
}

@RequestMapping(method = RequestMethod.GET, path = "/{id}", produces = "application/json")
@ApiOperation("Returns a specific person by their identifier. 404 if does not exist.")
public Person getPersonById(@ApiParam("Id of the person to be obtained. Cannot be empty.")
                                @PathVariable int id) {
    return personService.getPersonById(id);
}

@RequestMapping(method = RequestMethod.DELETE, path = "/{id}")
@ApiOperation("Deletes a person from the system. 404 if the person's identifier is not found.")
public void deletePerson(@ApiParam("Id of the person to be deleted. Cannot be empty.")
                             @PathVariable int id) {
    personService.deletePerson(id);
}

@RequestMapping(method = RequestMethod.POST, produces = "application/json")
@ApiOperation("Creates a new person.")
public Person createPerson(@ApiParam("Person information for a new person to be created.")
                               @RequestBody Person person) {
    return personService.createPerson(person);
}

@Autowired
public void setPersonService(PersonService personService) {
    this.personService = personService;
}

}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值