一、集成方法
1.引入swagger依赖
在pom文件中引入swagger相关依赖
<!-- 配置swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
2.创建swagger配置类
在项目中创建自己的swagger配置类,名称任意,关键是要加上swagger的注解@EnableSwagger2
//swagger注解
@EnableSwagger2
public class ApplicationSwaggerConfig {
}
3.引入swagger资源文件以及配置类
在spring的mvc配置文件中,引入swagger资源文件以及配置类,注意配置类的名称以及包名要与步骤2对应。
<!-- 引入swagger资源文件 -->
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<!-- 将swagger配置类放入ioc容器中 -->
<bean name="applicationSwaggerConfig" class="com.limingkang.swagger.ApplicationSwaggerConfig"/>
4.使用swaggerAPI注解配置接口
在接口类的类名和方法名使用swaggerAPI的注解,此处仅做举例,重点是swaggerAPI的注解,请忽略具体代码。
//类名的api注解
@Api(value = "秒杀", description = "秒杀")
@Controller
@RequestMapping("/seckill")
public class SeckillController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private SeckillService seckillService;
//方法名的api注解
@ApiOperation(value = "秒杀列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Model model) {
List<Secki