Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the @ ApiIgnore annotation in Swagger

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use the @ ApiIgnore annotation in Swagger, which has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.

Use of Swagger @ ApiIgnore annotations

@ ApiIgnore can be used on classes, methods, and method parameters to shield certain interfaces or parameters from being displayed on the page.

1. When acting on a class, the entire class will be ignored @ ApiIgnore@Api (tags = {"Xxx control class"}) @ RestController@RequestMapping ("/ xxx") public class XxxController {.}

To hide a class, you can also annotate its own hidden attribute with @ Api:

@ Api (value = "xxx", tags = "xxx", hidden = true)

This class is hidden when hidden is true.

2. When used in a method, the method will be ignored @ ApiIgnore@ApiOperation (value = "xxx", httpMethod = "POST", notes = "xxx") @ ApiImplicitParams ({@ ApiImplicitParam (name = "xxx", value = "xxx", paramType = "query", dataType = "String", required = true)}) @ PostMapping ("/ xxx") public Result importCarryEquExcel (String xxx) {.}

To hide a method, you can also annotate its own hidden attribute with @ APIOperation:

@ ApiOperation (value = "xxx", httpMethod = "GET", notes = "xxx", hidden = true)

This method is hidden when hidden is true.

3. When acting on parameters, a single specific parameter will be ignored public String abc (@ ApiIgnore String a, String b, String c) {return "a" + "b" + "c";}

Add:

4. Ways to ignore unwanted fields in entity classes

(1) annotate the hidden attribute that comes with @ ApiModelProperty:

@ ApiModelProperty (value = "xxxid", required = true,hidden = true) private Long id

(2) use @ JsonIgnore to comment:

@ ApiModelProperty (value = "xxxid", required = true) @ JsonIgnore private Long id

Package name:

Common comments in import com.fasterxml.jackson.annotation.JsonIgnore;Swagger

When using swagger

@ ApiOperation means to generate API documents

@ Apiignore means to ignore the build

@ ApiIgnore can be used on classes, methods, and method parameters to shield certain interfaces or parameters from being displayed on the page.

1. When acting on a class, the entire class will be ignored @ ApiIgnore@Api (tags = {"Xxx control class"}) @ RestController@RequestMapping ("/ xxx") public class XxxController {.}

To hide a class, you can also annotate its own hidden attribute with @ Api:

@ Api (value = "xxx", tags = "xxx", hidden = true) when hidden is true, this class hides 2 when it is used in a method Methods will be ignored @ ApiIgnore@ApiOperation (value = "xxx", httpMethod = "POST", notes = "xxx") @ ApiImplicitParams ({@ ApiImplicitParam (name = "xxx", value = "xxx", paramType = "query", dataType = "String", required = true)}) @ PostMapping ("/ xxx") public Result importCarryEquExcel (String xxx) {.}

To hide a method, you can also annotate its own hidden attribute with @ APIOperation

ApiIgnore@ApiOperation (value = "xxx", httpMethod = "POST", notes = "xxx") @ ApiImplicitParams ({@ ApiImplicitParam (name = "xxx", value = "xxx", paramType = "query", dataType = "String", required = true)}) @ PostMapping ("/ xxx") public Result importCarryEquExcel (String xxx) {.}

To hide a method, you can also annotate its own hidden attribute with @ APIOperation:

@ ApiOperation (value = "xxx", httpMethod = "GET", notes = "xxx", hidden = true)

When hidden is true, this method hides the

3. When acting on the parameters, a single specific parameter will be ignored public String abc (@ ApiIgnore String a, String b, String c) {return "a" + "b" + "c";} Thank you for reading this article carefully. I hope the article "how to use @ ApiIgnore annotations in Swagger" shared by the editor will be helpful to you. At the same time, I also hope you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report