“This is the 28th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”


Related articles

Java with Notes: Java with Notes


preface

  • The last article didn’t cover all the common annotations, so here are the last four.
  • There are some other notes, interested partners can study, here I do not repeat.
  • We usually in the development process, can be used as appropriate.
  • I hope it was helpful.
  • Don't abandon me water sub development, in order to more text activities, not shabby! Do you know!

A, ApiResponse

  • @ApiResponseUsed methodically to describe some information about an interface response.
  • @restController@API (tags = "Swagger test class ") public Class SwaggerTestController {@APIResponse (code = 200,message = "success", response = StudentResponse.class) @RequestMapping(value = "test-swagger",method = RequestMethod.GET) @ApiOperation(value = "query student details ",notes =" id") public StudentResponse dyTest(){return new StudentResponse(); }}Copy the code
  • The effect is as follows:

Second, the ApiResponses

  • This is just defined200Status code, if yes500?
  • @ApiResponsesIs more than one@ApiResponsePut it together.
  • @restController @API (tags = "Swagger test class ") public Class SwaggerTestController {// @apiResponse (code = 200,message = "success", response = StudentResponse.class) @ApiResponses({@ApiResponse(code = 200,message = "success", response = StudentResponse.class), @ApiResponse(code = 500,message = "failed", response = StudentResponse.class)}) @RequestMapping(value = "test-swagger",method = RequestMethod.GET) @apiOperation (value = "query student details ",notes =" id") public StudentResponse dyTest(){return new StudentResponse(); @apiOperation (value = "query student details ",notes =" id") public StudentResponse dyTest(){return new StudentResponse(); }}Copy the code
  • The effect is as follows:

Third, ApiImplicitParam

  • If we have fewer parameters, such as specifying data details by ID query, we can’t create a separate entity to describe it, can we?
  • Usually when we do, under five parameters can be passedApiImplicitParamTo describe the parameters.
  • Of course, onlyGetRequest, if it is to add, modify, etc.,Post,PutRequest entity class again!
  • @ApiImplicitParamUsed methodically to specify individual request parameters.
  • @restController@API (tags = "Swagger Test class ") Public Class SwaggerTestController {@apiResponses ({@apiResponse (code = 200,message = "success", response = StudentResponse.class), @ApiResponse(code = 500,message = "failed", response = StudentResponse.class)}) @RequestMapping(value = "test-swagger",method = RequestMethod.GET) @APIOperation (value = "query student details ",notes =" parameter id") @APIIMPLICITParam (name = "id", value = "student ID", dataType = "string", paramType = "query", required = true, defaultValue = "1") public StudentResponse dyTest(String id){ return new StudentResponse(); }}Copy the code
  • The effect is as follows:

Four, ApiImplicitParams

  • With multiple parameters,ApiImplicitParamMay not meet our requirements, this time need to assemble!
  • Again, multiple@ApiImplicitParamPut it together.
  • @restController@API (tags = "Swagger Test class ") Public Class SwaggerTestController {@apiResponses ({@apiResponse (code = 200,message = "success", response = StudentResponse.class), @ApiResponse(code = 500,message = "failed", response = StudentResponse.class)}) @RequestMapping(value = "test-swagger",method = RequestMethod.GET) @apiOperation (value = "query student details ",notes =" parameter id") // @apiIMPLICITParam (name = "id", value = "student id", dataType = "string", paramType = "query", required = true, defaultValue = "1") @ApiImplicitParams({@ApiImplicitParam(name = "id", Value = "student ID", dataType = "string", paramType = "query", Required = true, defaultValue = "1"), @APIIMPLICITParam (name = "name", value = "student name", dataType = "string", paramType = "query", Required = true, defaultValue = "1")}) public StudentResponse dyTest(String id){ return new StudentResponse(); }}Copy the code
  • The effect is as follows:

conclusion

  • hereSwaggerThe series is really over. There was nothing more to tell.
  • Read all the articles in this series and I’m sure you’re rightSwaggerYou have a relatively deep understanding.
  • Hope to help you, this series is not the most detailed network is about the same!
  • Ha ha ha, I can sort out a lot of just finally integrate out!
  • This series of articles are personal opinions, please point out if there are any mistakes
  • Light spray! Thank you ~

The road ahead is long, I see no end, I will search high and low

If you think I bloggers write well! Writing is not easy, please like, follow, comment and give encouragement to the blogger ~ Hahah