1.spring-fox依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
2.springBoot启动类上方添加注解(@EnableSwagger2,@EnableWebMvc)
@SpringBootApplication
@EnableSwagger2 //swagger2注解
@EnableWebMvc
public class SwaggerDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SwaggerDemoApplication.class, args);
}
}
3.常用注解
@api:
作用于控制层controller类上方,对controller说明
@apiOperation:
作用于url方法上,对方法进行说明
@ApiParam:
作用于参数前,对参数进行说明
@Controller
@Api(tags = {"swaggerController"},description = "描述") ///@Api作用于controller类上方
public class SwaggerController {
@GetMapping(value = {"/getpeople"})
@ResponseBody
@ApiOperation(value = "方法描述") /// @ApiOperation作用于方法上方
public String test2(@ApiParam(value = "学号ID",// @ApiParam作用于参数上
required = false) Integer id, String name){
System.out.println("swagger测试");
System.out.println(id+"----"+name);
return "Swagger测试";
}
}
@ApiModel:
作用于实体类上方
@ApiModelProperty:
作用于属性上方
@ApiModel(value = "people实体类")///@ApiModel作用于实体类上方
public class People {
private Integer id;
@ApiModelProperty(value = "姓名")///@ApiModelProperty作用于属性上方说明
private String name;
private String address;
}
博客:孤独&烙印的博客_CSDN博客-springSecurity,spring-fox,vue领域博主