如何在SpringBoot中对大摇大摆进行配置

  介绍

如何在SpringBoot中对大摇大摆进行配置?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。


, & lt; !——web方便测试——比;   ,,,& lt; dependency>   ,,,,,& lt; groupId> org.springframework.boot   ,,,,,& lt; artifactId> spring-boot-starter-web   ,,,& lt;/dependency>   ,,,& lt; !——, swagger2核心包,——比;   ,,,& lt; dependency>   ,,,,,& lt; groupId> io.springfox   ,,,,,& lt; artifactId> springfox-swagger2   ,,,,,& lt; version> 2.9.2   ,,,& lt;/dependency>   ,,,& lt; !——, swagger-ui 可视化界面,——比;   ,,,& lt; dependency>   ,,,,,& lt; groupId> io.springfox   ,,,,,& lt; artifactId> springfox-swagger-ui   ,,,,,& lt; version> 2.9.2   ,,,& lt;/dependency>

<强>大摇大摆可视化界面可分为三个区域

如何在SpringBoot中对大摇大摆进行配置

<强>大摇大摆相关配置

package  com.example.config;      import  org.springframework.context.annotation.Bean;   import  org.springframework.context.annotation.Configuration;   import  springfox.documentation.builders.RequestHandlerSelectors;   import  springfox.documentation.service.ApiInfo;   import  springfox.documentation.service.Contact;   import  springfox.documentation.spi.DocumentationType;   import  springfox.documentation.spring.web.plugins.Docket;   import  springfox.documentation.swagger2.annotations.EnableSwagger2;      import  java.util.ArrayList;      @ configuration   @EnableSwagger2 //开启大摇大摆的使用   public  class  SwaggerConfig  {      ,,@Bean //大摇大摆的使用主要是要将摘要对象传入奥委会容器   public 才能;Docket 摘要(){   ,,,return  new 摘要(DocumentationType.SWAGGER_2)   ,,,,,,,.apiInfo (apiInfo()),//关于文档的各种信息   ,,,,,,,.enable(真实),//使大摇大摆生效   ,,,,,,,.groupName(“常安祖“)   ,,,,,,,.select()//选择扫描的接口   ,,,,,,,.apis (RequestHandlerSelectors.basePackage (“com.example.controller"))//指定扫描的接口   ,,,,,,,.build ();   ,,}         public 才能;ApiInfo  apiInfo () {   ,,,Contact  Contact =, new 联系(“长安“,“https://blog.csdn.net/weixin_45647685",“719801748 @qq.com");//个人的联系方式   ,,,return  new  ApiInfo(“长安的文档”,,“长安的开发文档”,,“1.0”,,“urn: tos", null,,“Apache  2.0“,,,”http://www.apache.org/licenses/license - 2.0“,, new  ArrayList());//文档的各种信息   ,,}   }

<>强@ApiModel() //主要用来标注返回的实体类
<强> @ApiModelProperty() //主要用来标注实体类中的属性
案例:

@ApiModel(“用户的实体类“)   public  class  User  implements  Serializable  {      @ApiModelProperty才能(“用户的id")   private 才能Integer  id;      @ApiModelProperty才能(“用户的姓名“)   private 才能;String 名称;      @ApiModelProperty才能(“用户的年纪“)   private 才能;Integer 年龄;      public 才能;Integer  getId (), {   ,,,return  id;   ,,}   public 才能;用户(Integer  id, String 名字,,Integer 年龄),{   ,,,this.id =, id;   ,,,this.name =,名称;   ,,,this.age =,年龄;   ,,}      public 才能;void  setId (Integer  id), {   ,,,this.id =, id;   ,,}      public 才能;String  getName (), {   ,,,return 名称;   ,,}      public 才能;void  setName (String 名称),{   ,,,this.name =,名称;   ,,}      public 才能;Integer  getAge (), {   ,,,return 年龄;   ,,}      public 才能;void  setAge (Integer 年龄),{   ,,,this.age =,年龄;   ,,}   }

<>强@ApiModelProperty 用来标注API接口
案例:

package  com.yangzihao.controller;      import  com.yangzihao.entity.User;   import  io.swagger.annotations.ApiModelProperty;   null   null   null   null   null   null   null   null   null   null   null   null   null

如何在SpringBoot中对大摇大摆进行配置