SSM接口可视化

1 工具

2 配置

2.1 pom.xml

<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.2 接口配置类

  • ApplicationShow.java
package com.document;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
// import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.service.ApiInfo;

@Configuration
@EnableSwagger2
@EnableWebMvc
@ComponentScan(basePackages="com.controller.bigdata")
// public class ApplicationShow extends WebMvcConfigurationSupport{
public class ApplicationShow{
    @Bean 
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("接口可视化")
                .version("1.0.0")
                .termsOfServiceUrl("")
                .license("")
                .licenseUrl("")
                .build();

    }
}

2.3 静态文件

  • 路径:新建文件夹/api-document/version2
    /webapp/api-document/version2
  • github的dist文件夹中的全部文件拷贝至version2文件夹下
  • 映射配置
<!--配置接口类-->
<bean class="com.document.ApplicationShow"/>
<!--静态文件-->
<mvc:resources location="/api-document/" mapping="/api-document/**"/>

2.4 url配置

/webapp/api-document/version2/index.html

url:http://localhost:8080/{artifactId}/v2/api-docs/index.html
http://localhost:8080/project/v2/api-docs/index.html

2.5 controller配置

package com.controller.bigdata;

import java.util.Map;

import ***.po.className;
import ***.service.classNameService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller 
@RequestMapping("/api")
@Api(value="/api", tags="功能测试", description="数据搜索性能分析")
public class TestController{
    @Autowired
    private DeviceStatusService deviceStatusService;

    @RequestMapping(value="/get-infos", params="id", method=RequestMethod.POST)
    @ResponseBody 
    @ApiOperation(value="通过id查询数据")
    public Map mapReturn(@RequestPamram("id") Integer id){
        return infos;
    }
}

2.6 中文

/webapp/api-document/version2/index.html

<script src='lang/translator.js' type='text/javascript'></script>
<script src='lang/zh-cn.js' type='text/javascript'></script>

3 接口界面

在这里插入图片描述

图3.1 接口界面

【参考文献】
[1]https://segmentfault.com/a/1190000010465989
[2]https://www.cnblogs.com/jtlgb/p/6734177.html
[3]https://blog.csdn.net/qq_42291606/article/details/87808052
[4]https://github.com/swagger-api/swagger-ui

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天然玩家

坚持才能做到极致

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值