Swagger使用(2)

一、启动Spring Boot程序,访问:http://localhost:8080/swagger-ui.html

二、Swagger标签 

在controller软件包下MoneyHandler 类

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

 

@RestController
@RequestMapping("/money")
@Api(tags = "操作money表访问接口")
public class MoneyHandler {  

  @ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息")
  @GetMapping("/findAll")
  public List<Money> findAll(){}


@ApiOperation(value="创建用户", notes="根据User对象创建用户")
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
@RequestMapping(value="", method=RequestMethod.POST)
public String postUser(@RequestBody User user) {}

   

@ApiOperation(value="更新用户详细信息", notes="根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
})
@RequestMapping(value="/{id}", method=RequestMethod.PUT)
public String putUser(@PathVariable Long id, @RequestBody User user) {}

 

@ApiOperation(value="删除用户", notes="根据url的id来指定删除对象")
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
public String deleteUser(@PathVariable Long id) {}

 

说明:

@API(tags="说明该类的作用")


@ApiOperation(value=“接口说明”, notes = “接口发布说明”)


@ApiParam (required = "是否必须参数(true or false)",  value = "参数汉字说明,解释" , name = "参数名" )

posted @ 2021-05-10 16:49  寒冷的雨呢  阅读(88)  评论(0编辑  收藏  举报