Swagger中注解 — ApiOperation

@ApiOperation
  1. 首先@ApiOperation注解不是Spring自带的,它是是swagger里的
  2. 注解@ApiOperation是用来构建Api文档的
  3. @ApiOperation(value = “接口说明”,httpMethod = “接口请求方式”, response =“接口返回参数类型”, notes = “接口发布说明”;其他参数可参考源码;

写个栗子:

  @ApiOperation(value = "添加")
    @PostMapping("addBanner")
    public R addBanner(@RequestBody Banner banner){
        bannerService.save(banner);
        return R.ok();
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping("{id}")
    public R getBanner(@PathVariable String id){
        Banner banner = bannerService.getById(id);
        return R.ok().data("banner",banner);
    }

    @ApiOperation(value = "修改")
    @PostMapping("updateBanner")
    public R updateBanner(@RequestBody Banner banner){
        bannerService.updateById(banner);
        return R.ok();
    }
    @ApiOperation(value = "根据id删除")
    @DeleteMapping("{id}")
    public R deleteBanner(@PathVariable String id){
        bannerService.removeById(id);
        return R.ok();
    }

源码:

package io.swagger.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiOperation {
    String value();

    String notes() default "";

    String[] tags() default {""};

    Class<?> response() default Void.class;

    String responseContainer() default "";

    String responseReference() default "";

    String httpMethod() default "";

    /** @deprecated */
    @Deprecated
    int position() default 0;

    String nickname() default "";

    String produces() default "";

    String consumes() default "";

    String protocols() default "";

    Authorization[] authorizations() default {@Authorization("")};

    boolean hidden() default false;

    ResponseHeader[] responseHeaders() default {@ResponseHeader(
    name = "",
    response = Void.class
)};

    int code() default 200;

    Extension[] extensions() default {@Extension(
    properties = {@ExtensionProperty(
    name = "",
    value = ""
)}
)};
}

你可能感兴趣的:(swagger)