四、swagger的简单使用

一、swagger的简单使用:

  第一步:引入依赖: 

<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

第二步:在启动类上配置EnableSwagger2注解

  

@SpringBootApplication
@MapperScan(value = "com.cg.mysec.mapper")
@EnableSwagger2
public class SecurityDemoApplication {

public static void main(String[] args) {
SpringApplication.run(SecurityDemoApplication.class, args);
}

@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
}

第三步:启动项目,用浏览器访问swagger文档
  访问链接:http://localhost:8080/swagger-ui.html

二、swagger常用的三个注解

  1、@ApiOperation(value = "作用于方法上,对方法的描述")

  2、@ApiModelProperty(value = "作用在实体类属性上,对实体类属性的说明")

  3、@ApiParam(value = "作用在当个入参上,对该入参的说明")

 

三、注意事项,使用swagger时,请求方式应当使用Restful风格,否则文档会生成所有请求方式的接口文档

 

posted @ 2019-07-11 19:29  斩你形神,明我道心  阅读(345)  评论(0)    收藏  举报