SpringMVC集成Swagger

一、集成方法

    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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值