“This is the 22nd 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

  • We’re done with filtering, but today we’re going to focus on grouping.
  • When the project was large in the past, a team might not be able to meet our needs.
  • We need to group the different features of the project for easy viewing and differentiation.

GroupName group ()

  • First of all, what are the default groups? Start the project.

  • There is only one group by default.

  • The source code is as follows:

    • /** * If more than one instance of Docket exists, each one must have a unique groupName as * supplied by this method. Defaults to "default". * * @param groupName - the unique identifier of this swagger group/configuration * @return this Docket */ public Docket groupName(String groupName)  { this.groupName = defaultIfAbsent(groupName, this.groupName); return this; }Copy the code
  • What about the value of this.groupName?

  • It follows that when groupName() is not set, there is only one default group.

  • User-defined group name

    •     @Bean
          public Docket docket(){
              return new Docket(DocumentationType.SWAGGER_2)
                      .apiInfo(apiInfo())
                      .groupName("group1")
                      .enable(swaggerModel.isEnable())
                      .select()
                      .paths(PathSelectors.any())
                      .build();
          }
      Copy the code
  • Start the project again and see

  • Ok! That’s it! We’ve set up a group!

  • So what if we have multiple groups?

  • As mentioned in the previous article, we use Docket to control Swagger configuration.

  • You only need to set up multiple dockets.

  • The code is as follows:

    • @Bean public Docket docket1(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("group1") .enable(swaggerModel.isEnable()) .select() .paths(PathSelectors.any()) .build(); } @Bean public Docket docket2(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("group2")  .enable(swaggerModel.isEnable()) .select() .paths(PathSelectors.any()) .build(); } @Bean public Docket docket3(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("group3")  .enable(swaggerModel.isEnable()) .select() .paths(PathSelectors.any()) .build(); }Copy the code
    • Restart the project again

    • Nice! Multiple groups set successfully!

conclusion

  • What if it’s in actual project development?
  • Because there are multipleDocket, eachDocketCan be set to a group, of course, can be set to eachDocketSeparate filtering rules for
  • This is perfectly set up as one large functional module with one group.
  • It is convenient for the front end to find the corresponding interface information according to the function.
  • Why?
  • Because when you get big, you can have hundreds or thousands of interfaces. If all in a group, look for special trouble!
  • whilegroupName()Can be very convenient to help us avoid this problem!
  • The above are all personal words, if there is any wrong, welcome to point out.
  • If it is helpful to you, I hope to like a point of concern! Let’s continue tomorrowSwaggerThe interpretation of!

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