业务流程

上一章节我们构建了前端管理页面api-gateway-admin,本章节我么要干的就是再api-gateway-center中提供前端页面的查询接口。就是纯粹的查询(不过要注意分页),同时要注意前后端联调的跨域问题。

跨域访问是指当一个网页从一个域名(或端口)请求另一个域名(或端口)的资源时,由于浏览器的同源策略限制,请求会被拒绝。跨域访问是一种常见的安全限制,用于防止网页在不受信任的域中访问敏感信息。

@CrossOrigin 是一个跨域配置的注解,可以指定可访问接口的跨越域名和端口,如果什么都不配置,那么默认就是都可以访问。

另外关于跨域还有其他的解决方案;

  1. 使用代理服务器,将请求转发到目标域。

  2. 使用 JSONP 技术,通过动态创建 script 标签来请求数据。

  3. 使用 CORS(Cross-Origin Resource Sharing)技术,通过在服务器端设置 HTTP 头来允许跨域访问。也就是咱们使用的注解方式。

  4. 使用服务器端框架或库,例如 Spring 或 Apache Shiro,提供跨域访问支持。

  5. 使用 Nginx 代理服务器,在服务器端配置跨域访问。

  6. 使用WebSocket,建立双向通信,消除跨域问题

业务实现

分页查询准备

在数据库查询或接口返回数据时,数据量可能非常庞大,比如用户表有上百万行。如果一次性把所有数据返回到前端:

  • 内存压力大(一次性加载几万甚至百万行数据,会卡死应用)。

  • 网络传输慢(HTTP 响应体太大,耗时长)。

  • 用户体验差(前端渲染慢,滚动卡顿)。

所以通常采用 分页查询,即:

  • 每次只取一小部分数据(比如 10 条、20 条)。

  • 用户翻页时再查询下一部分。

分页通常依赖三个核心参数:

  1. pageIndex / pageNum(页码)

    • 表示当前第几页。

    • 一般从 1 开始(有些从 0 开始)。

  2. pageSize / rows(每页条数)

    • 表示一页返回多少条记录。

  3. offset(偏移量)

    • 用于数据库 SQL 查询:从第几条开始取。

    • 常见写法:

       SELECT * FROM table LIMIT offset, pageSize;
    • 其中:

      • offset = (pageIndex - 1) * pageSize

      • pageSize 就是每页数量。

因此我们这里对于分页查询的请求和响应结果有如下

首先是查询请求的封装OperationRequest.java,其中pageIndex,pageSize是前端传递进来的当前查询页面参数,而pageStart,pageEnd则是我们在进行sql查询是所用的参数,其实pageIndex,pageSize与pageStart,pageEnd数值是相同的,但是为了不让其使用过程哦那个前端传递进来的数值与sql查询的混淆,我们才创建了不同的参数。

 package com.zshunbao.gateway.center.infrastructure.common;
 ​
 import org.apache.commons.lang3.StringUtils;
 ​
 /**
  * @program: api-gateway-center
  * @ClassName OperationRequest
  * @description: 前端页面请求数据类型,分页
  * @author: zs宝
  * @create: 2025-09-05 16:01
  * @Version 1.0
  **/
 public class OperationRequest<T> {
     private int pageStart;
     private int pageEnd;
     private int pageIndex;
     private int pageSize;
     private T data;
 ​
     public OperationRequest() {
     }
 ​
     public OperationRequest(String page, String rows) {
         //若传进来的当前页码为空,则跳转至首页
         this.pageIndex= StringUtils.isEmpty(page)?1:Integer.parseInt(page);
         //默认,每页大小为10
         this.pageSize=StringUtils.isEmpty(page)?10:Integer.parseInt(rows);
         //避免页码为0
         if(0==this.pageIndex){
             this.pageIndex=1;
         }
         //分页的计算公式,limit offset pagesize
         this.pageStart=(pageIndex-1)*this.pageSize;
         this.pageEnd=this.pageSize;
     }
 ​
     /**
      * 参数类型变化,实质还是在计算分页公式
      * @param page
      * @param rows
      */
     public OperationRequest(int page, int rows) {
         this.pageIndex = 0 == page ? 1 : page;
         this.pageSize = 0 == rows ? 10 : rows;
         this.pageStart = (this.pageIndex - 1) * this.pageSize;
         this.pageEnd = this.pageSize;
     }
 ​
     //设置当前页的数据位置
     public void setPage(String page, String rows) {
         //若传进来的当前页码为空,则跳转至首页
         this.pageIndex= StringUtils.isEmpty(page)?1:Integer.parseInt(page);
         //默认,每页大小为10
         this.pageSize=StringUtils.isEmpty(page)?10:Integer.parseInt(rows);
         //避免页码为0
         if(0==this.pageIndex){
             this.pageIndex=1;
         }
         //分页的计算公式,limit offset pagesize
         this.pageStart=(pageIndex-1)*this.pageSize;
         this.pageEnd=this.pageSize;
     }
 ​
     public int getPageStart() {
         return pageStart;
     }
 ​
     public void setPageStart(int pageStart) {
         this.pageStart = pageStart;
     }
 ​
     public int getPageEnd() {
         return pageEnd;
     }
 ​
     public void setPageEnd(int pageEnd) {
         this.pageEnd = pageEnd;
     }
 ​
     public T getData() {
         return data;
     }
 ​
     public void setData(T data) {
         //当data传进类空字符串时,将其转为null,避免 SQL 查询条件出问题。
         if(data instanceof String){
             String str=(String)data;
             if (StringUtils.isEmpty(str)){
                 data=null;
             }
         }
         this.data=data;
     }
 }
 ​

响应结果OperationResult.java,分页查询,既要有数据,又要有数据条数

 package com.zshunbao.gateway.center.infrastructure.common;
 ​
 import java.util.List;
 ​
 /**
  * @program: api-gateway-center
  * @ClassName OperationResult
  * @description:
  * @author: zs宝
  * @create: 2025-09-05 16:03
  * @Version 1.0
  **/
 public class OperationResult<T>{
     private int pageTotal;
     private List<T> list;
 ​
     public OperationResult(){
     }
 ​
     public OperationResult(int pageTotal, List<T> list){
         this.pageTotal = pageTotal;
         this.list = list;
     }
 ​
     public int getPageTotal() {
         return pageTotal;
     }
 ​
     public void setPageTotal(int pageTotal) {
         this.pageTotal = pageTotal;
     }
 ​
     public List<T> getList() {
         return list;
     }
 ​
     public void setList(List<T> list) {
         this.list = list;
     }
 }
 ​

对外前端接口实现

这一块其实也就没有什么了,无非是根据前端传来的数据分别对网关中心的库表进行分页查询。直接看代码

首先是对外的访问接口(注意跨域)

DataOperationManage.java

 package com.zshunbao.gateway.center.interfaces;
 ​
 import com.alibaba.fastjson.JSON;
 import com.zshunbao.gateway.center.application.IDataOperationManageService;
 import com.zshunbao.gateway.center.domain.operation.model.vo.*;
 import com.zshunbao.gateway.center.infrastructure.common.OperationRequest;
 import com.zshunbao.gateway.center.infrastructure.common.OperationResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.*;
 ​
 import javax.annotation.Resource;
 ​
 /**
  * @program: api-gateway-center
  * @ClassName DataOperationManage
  * @description: 网关数据操作管理,针对前端页面的接口
  * @author: zs宝
  * @create: 2025-09-05 16:21
  * @Version 1.0
  **/
 @CrossOrigin
 @RestController
 @RequestMapping("/wg/admin/data")
 public class DataOperationManage {
     private Logger logger = LoggerFactory.getLogger(DataOperationManage.class);
 ​
     @Resource
     private IDataOperationManageService dataOperationManageService;
 ​
     @GetMapping(value = "queryGatewayServer", produces = "application/json;charset=utf-8")
     public OperationResult<GatewayServerDataVO> queryGatewayServer(@RequestParam String groupId,
                                                                    @RequestParam String page,
                                                                    @RequestParam String limit) {
         try {
             logger.info("查询网关服务数据开始 groupId:{} page:{} limit:{}", groupId, page, limit);
             OperationRequest<String> req = new OperationRequest<>(page, limit);
             req.setData(groupId);
             OperationResult<GatewayServerDataVO> operationResult = dataOperationManageService.queryGatewayServer(req);
             logger.info("查询网关服务数据完成 operationResult:{}", JSON.toJSONString(operationResult));
             return operationResult;
         } catch (Exception e) {
             logger.error("查询网关服务数据异常 groupId:{}", groupId, e);
             return new OperationResult<>(0, null);
         }
     }
 ​
     @GetMapping(value = "queryGatewayServerDetail", produces = "application/json;charset=utf-8")
     public OperationResult<GatewayServerDetaiDatalVO> queryGatewayServerDetail(@RequestParam String groupId,
                                                                                @RequestParam String gatewayId,
                                                                                @RequestParam String page,
                                                                                @RequestParam String limit) {
         try {
             logger.info("查询网关服务详情数据开始 groupId:{} gatewayId:{} page:{} limit:{}", groupId, gatewayId, page, limit);
             GatewayServerDetaiDatalVO data=new GatewayServerDetaiDatalVO(groupId,gatewayId);
             OperationRequest<GatewayServerDetaiDatalVO>req=new OperationRequest<>(page,limit);
             req.setData(data);
             OperationResult<GatewayServerDetaiDatalVO> operationResult = dataOperationManageService.queryGatewayServerDetail(req);
             logger.info("查询网关服务详情数据完成 operationResult:{}", JSON.toJSONString(operationResult));
             return operationResult;
         }catch (Exception e){
             logger.error("查询网关服务详情数据异常 groupId:{}  gatewayId:{}", groupId,gatewayId, e);
             return new OperationResult<>(0, null);
         }
     }
 ​
 ​
     @GetMapping(value = "queryGatewayDistribution", produces = "application/json;charset=utf-8")
     public OperationResult<GatewayDistributionDataVO> queryGatewayDistribution(@RequestParam String groupId,
                                                                                @RequestParam String gatewayId,
                                                                                @RequestParam String page,
                                                                                @RequestParam String limit) {
         try {
             logger.info("查询网关分配数据开始 groupId:{} gatewayId:{} page:{} limit:{}", groupId, gatewayId, page, limit);
             OperationRequest<GatewayDistributionDataVO> req = new OperationRequest<>(page, limit);
             req.setData(new GatewayDistributionDataVO(groupId, gatewayId));
             OperationResult<GatewayDistributionDataVO> operationResult = dataOperationManageService.queryGatewayDistribution(req);
             logger.info("查询网关分配数据完成 operationResult:{}", JSON.toJSONString(operationResult));
             return operationResult;
         } catch (Exception e) {
             logger.error("查询网关分配数据异常 groupId:{}", groupId, e);
             return new OperationResult<>(0, null);
         }
     }
 ​
     @GetMapping(value = "queryApplicationSystem", produces = "application/json;charset=utf-8")
     public OperationResult<ApplicationSystemDataVO> queryApplicationSystem(@RequestParam String systemId,
                                                                            @RequestParam String systemName,
                                                                            @RequestParam String page,
                                                                            @RequestParam String limit) {
         try {
             logger.info("查询应用系统信息开始 systemId:{} systemName:{} page:{} limit:{}", systemId, systemName, page, limit);
             OperationRequest<ApplicationSystemDataVO> req = new OperationRequest<>(page, limit);
             req.setData(new ApplicationSystemDataVO(systemId, systemName));
             OperationResult<ApplicationSystemDataVO> operationResult = dataOperationManageService.queryApplicationSystem(req);
             logger.info("查询应用系统信息完成 operationResult:{}", JSON.toJSONString(operationResult));
             return operationResult;
         } catch (Exception e) {
             logger.error("查询应用系统信息异常 systemId:{} systemName:{}", systemId, systemId, e);
             return new OperationResult<>(0, null);
         }
     }
 ​
     @GetMapping(value = "queryApplicationInterface", produces = "application/json;charset=utf-8")
     public OperationResult<ApplicationInterfaceDataVO> queryApplicationInterface(@RequestParam String systemId,
                                                                                  @RequestParam String interfaceId,
                                                                                  @RequestParam String page,
                                                                                  @RequestParam String limit) {
         try {
             logger.info("查询应用接口信息开始 systemId:{} interfaceId:{} page:{} limit:{}", systemId, interfaceId, page, limit);
             OperationRequest<ApplicationInterfaceDataVO> req = new OperationRequest<>(page, limit);
             req.setData(new ApplicationInterfaceDataVO(systemId, interfaceId));
             OperationResult<ApplicationInterfaceDataVO> operationResult = dataOperationManageService.queryApplicationInterface(req);
             logger.info("查询应用接口信息完成 operationResult:{}", JSON.toJSONString(operationResult));
             return operationResult;
         } catch (Exception e) {
             logger.error("查询应用接口信息异常 systemId:{} interfaceId:{}", systemId, interfaceId, e);
             return new OperationResult<>(0, null);
         }
     }
 ​
     @GetMapping(value = "queryApplicationInterfaceMethodList", produces = "application/json;charset=utf-8")
     public OperationResult<ApplicationInterfaceMethodDataVO> queryApplicationInterfaceMethodList(@RequestParam String systemId,
                                                                                                  @RequestParam String interfaceId,
                                                                                                  @RequestParam String page,
                                                                                                  @RequestParam String limit) {
         try {
             logger.info("查询应用接口方法信息开始 systemId:{} interfaceId:{} page:{} limit:{}", systemId, interfaceId, page, limit);
             OperationRequest<ApplicationInterfaceMethodDataVO> req = new OperationRequest<>(page, limit);
             req.setData(new ApplicationInterfaceMethodDataVO(systemId, interfaceId));
             OperationResult<ApplicationInterfaceMethodDataVO> operationResult = dataOperationManageService.queryApplicationInterfaceMethod(req);
             logger.info("查询应用接口方法信息完成 operationResult:{}", JSON.toJSONString(operationResult));
             return operationResult;
         } catch (Exception e) {
             logger.error("查询应用接口方法信息异常 systemId:{} interfaceId:{}", systemId, interfaceId, e);
             return new OperationResult<>(0, null);
         }
     }
 ​
 }
 ​

然后是DDD模型对应的服务实现

j接口IDataOperationManageService.java

 package com.zshunbao.gateway.center.application;
 ​
 import com.zshunbao.gateway.center.domain.operation.model.vo.*;
 import com.zshunbao.gateway.center.infrastructure.common.OperationRequest;
 import com.zshunbao.gateway.center.infrastructure.common.OperationResult;
 ​
 /**
  * @program: api-gateway-center
  * @ClassName IDataOperationManageService
  * @description: 网关运营数据管理
  * @author: zs宝
  * @create: 2025-09-05 15:56
  * @Version 1.0
  **/
 public interface IDataOperationManageService {
     OperationResult<GatewayServerDataVO> queryGatewayServer(OperationRequest<String> request);
 ​
     OperationResult<ApplicationSystemDataVO> queryApplicationSystem(OperationRequest<ApplicationSystemDataVO> request);
 ​
     OperationResult<ApplicationInterfaceDataVO> queryApplicationInterface(OperationRequest<ApplicationInterfaceDataVO> request);
 ​
     OperationResult<ApplicationInterfaceMethodDataVO> queryApplicationInterfaceMethod(OperationRequest<ApplicationInterfaceMethodDataVO> request);
 ​
     OperationResult<GatewayServerDetaiDatalVO> queryGatewayServerDetail(OperationRequest<GatewayServerDetaiDatalVO> request);
 ​
     OperationResult<GatewayDistributionDataVO> queryGatewayDistribution(OperationRequest<GatewayDistributionDataVO> request);
 ​
 }
 ​

实现类DataOperationManageService.java

 package com.zshunbao.gateway.center.domain.operation.service;
 ​
 import com.zshunbao.gateway.center.application.IDataOperationManageService;
 import com.zshunbao.gateway.center.domain.operation.model.vo.*;
 import com.zshunbao.gateway.center.domain.operation.repository.IDataOperationManageRepository;
 import com.zshunbao.gateway.center.infrastructure.common.OperationRequest;
 import com.zshunbao.gateway.center.infrastructure.common.OperationResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 ​
 import javax.annotation.Resource;
 import java.util.List;
 ​
 /**
  * @program: api-gateway-center
  * @ClassName DataOperationManageService
  * @description:
  * @author: zs宝
  * @create: 2025-09-05 16:00
  * @Version 1.0
  **/
 @Service
 public class DataOperationManageService implements IDataOperationManageService {
     private Logger logger = LoggerFactory.getLogger(DataOperationManageService.class);
 ​
     @Resource
     private IDataOperationManageRepository repository;
 ​
     @Override
     public OperationResult<GatewayServerDataVO> queryGatewayServer(OperationRequest<String> request) {
         List<GatewayServerDataVO> list = repository.queryGatewayServerListByPage(request);
         int count = repository.queryGatewayServerListCountByPage(request);
         return new OperationResult<>(count, list);
     }
 ​
     @Override
     public OperationResult<ApplicationSystemDataVO> queryApplicationSystem(OperationRequest<ApplicationSystemDataVO> request) {
         List<ApplicationSystemDataVO> list = repository.queryApplicationSystemListByPage(request);
         int count = repository.queryApplicationSystemListCountByPage(request);
         return new OperationResult<>(count, list);
     }
 ​
     @Override
     public OperationResult<ApplicationInterfaceDataVO> queryApplicationInterface(OperationRequest<ApplicationInterfaceDataVO> request) {
         List<ApplicationInterfaceDataVO> list = repository.queryApplicationInterfaceListByPage(request);
         int count = repository.queryApplicationInterfaceListCountByPage(request);
         return new OperationResult<>(count, list);
     }
 ​
     @Override
     public OperationResult<ApplicationInterfaceMethodDataVO> queryApplicationInterfaceMethod(OperationRequest<ApplicationInterfaceMethodDataVO> request) {
         List<ApplicationInterfaceMethodDataVO> list = repository.queryApplicationInterfaceMethodListByPage(request);
         int count = repository.queryApplicationInterfaceMethodListCountByPage(request);
         return new OperationResult<>(count, list);
     }
 ​
     @Override
     public OperationResult<GatewayServerDetaiDatalVO> queryGatewayServerDetail(OperationRequest<GatewayServerDetaiDatalVO> request) {
         List<GatewayServerDetaiDatalVO> list = repository.queryGatewayServerDetailListByPage(request);
         int count = repository.queryGatewayServerDetailListCountByPage(request);
         return new OperationResult<>(count, list);
     }
 ​
     @Override
     public OperationResult<GatewayDistributionDataVO> queryGatewayDistribution(OperationRequest<GatewayDistributionDataVO> request) {
         List<GatewayDistributionDataVO> list = repository.queryGatewayDistributionListByPage(request);
         int count = repository.queryGatewayDistributionListCountByPage(request);
         return new OperationResult<>(count, list);
     }
 }
 ​

其次是仓储层实现DataOperationManageRepository.java

 package com.zshunbao.gateway.center.infrastructure.repository;
 ​
 import com.zshunbao.gateway.center.domain.operation.model.vo.*;
 import com.zshunbao.gateway.center.domain.operation.repository.IDataOperationManageRepository;
 import com.zshunbao.gateway.center.infrastructure.common.OperationRequest;
 import com.zshunbao.gateway.center.infrastructure.dao.*;
 import com.zshunbao.gateway.center.infrastructure.po.*;
 import org.springframework.stereotype.Component;
 ​
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
 ​
 ​
 /**
  * @program: api-gateway-center
  * @ClassName DataOperationManageRepository
  * @description:
  * @author: zs宝
  * @create: 2025-09-05 16:39
  * @Version 1.0
  **/
 @Component
 public class DataOperationManageRepository  implements IDataOperationManageRepository {
     @Resource
     private IGatewayServerDao gatewayServerDao;
     @Resource
     private IGatewayServerDetailDao gatewayServerDetailDao;
     @Resource
     private IGatewayDistributionDao gatewayDistributionDao;
     @Resource
     private IApplicationSystemDao applicationSystemDao;
     @Resource
     private IApplicationInterfaceDao applicationInterfaceDao;
     @Resource
     private IApplicationInterfaceMethodDao applicationInterfaceMethodDao;
 ​
     @Override
     public List<GatewayServerDataVO> queryGatewayServerListByPage(OperationRequest<String> request) {
         List<GatewayServer> gatewayServers = gatewayServerDao.queryGatewayServerListByPage(request);
         List<GatewayServerDataVO> gatewayServerVOList = new ArrayList<>(gatewayServers.size());
         for (GatewayServer gatewayServer : gatewayServers) {
             GatewayServerDataVO gatewayServerVO = new GatewayServerDataVO();
             gatewayServerVO.setId(gatewayServer.getId());
             gatewayServerVO.setGroupId(gatewayServer.getGroupId());
             gatewayServerVO.setGroupName(gatewayServer.getGroupName());
             gatewayServerVOList.add(gatewayServerVO);
         }
         return gatewayServerVOList;
     }
 ​
     @Override
     public int queryGatewayServerListCountByPage(OperationRequest<String> request) {
         return gatewayServerDao.queryGatewayServerListCountByPage(request);
     }
 ​
     @Override
     public List<ApplicationSystemDataVO> queryApplicationSystemListByPage(OperationRequest<ApplicationSystemDataVO> request) {
         List<ApplicationSystem> applicationSystems = applicationSystemDao.queryApplicationSystemListByPage(request);
         List<ApplicationSystemDataVO> applicationSystemDataVOList = new ArrayList<>(applicationSystems.size());
         for (ApplicationSystem applicationSystem : applicationSystems) {
             ApplicationSystemDataVO applicationSystemDataVO = new ApplicationSystemDataVO();
             applicationSystemDataVO.setSystemId(applicationSystem.getSystemId());
             applicationSystemDataVO.setSystemName(applicationSystem.getSystemName());
             applicationSystemDataVO.setSystemType(applicationSystem.getSystemType());
             applicationSystemDataVO.setSystemRegistry(applicationSystem.getSystemRegistry());
             applicationSystemDataVOList.add(applicationSystemDataVO);
         }
         return applicationSystemDataVOList;
     }
 ​
     @Override
     public int queryApplicationSystemListCountByPage(OperationRequest<ApplicationSystemDataVO> request) {
         return applicationSystemDao.queryApplicationSystemListCountByPage(request);
     }
 ​
     @Override
     public List<ApplicationInterfaceDataVO> queryApplicationInterfaceListByPage(OperationRequest<ApplicationInterfaceDataVO> request) {
         List<ApplicationInterface> applicationInterfaces = applicationInterfaceDao.queryApplicationInterfaceListByPage(request);
         List<ApplicationInterfaceDataVO> applicationInterfaceDataVOList = new ArrayList<>(applicationInterfaces.size());
         for (ApplicationInterface applicationInterface : applicationInterfaces) {
             ApplicationInterfaceDataVO applicationInterfaceDataVO = new ApplicationInterfaceDataVO();
             applicationInterfaceDataVO.setSystemId(applicationInterface.getSystemId());
             applicationInterfaceDataVO.setInterfaceId(applicationInterface.getInterfaceId());
             applicationInterfaceDataVO.setInterfaceName(applicationInterface.getInterfaceName());
             applicationInterfaceDataVO.setInterfaceVersion(applicationInterface.getInterfaceVersion());
             applicationInterfaceDataVOList.add(applicationInterfaceDataVO);
         }
         return applicationInterfaceDataVOList;
     }
 ​
     @Override
     public int queryApplicationInterfaceListCountByPage(OperationRequest<ApplicationInterfaceDataVO> request) {
         return applicationInterfaceDao.queryApplicationInterfaceListCountByPage(request);
     }
 ​
     @Override
     public List<ApplicationInterfaceMethodDataVO> queryApplicationInterfaceMethodListByPage(OperationRequest<ApplicationInterfaceMethodDataVO> request) {
         List<ApplicationInterfaceMethod> applicationInterfaceMethods = applicationInterfaceMethodDao.queryApplicationInterfaceMethodListByPage(request);
         List<ApplicationInterfaceMethodDataVO> applicationInterfaceMethodDataVOList = new ArrayList<>(applicationInterfaceMethods.size());
         for (ApplicationInterfaceMethod applicationInterfaceMethod : applicationInterfaceMethods) {
             ApplicationInterfaceMethodDataVO applicationInterfaceMethodDataVO = new ApplicationInterfaceMethodDataVO();
             applicationInterfaceMethodDataVO.setSystemId(applicationInterfaceMethod.getSystemId());
             applicationInterfaceMethodDataVO.setInterfaceId(applicationInterfaceMethod.getInterfaceId());
             applicationInterfaceMethodDataVO.setMethodId(applicationInterfaceMethod.getMethodId());
             applicationInterfaceMethodDataVO.setMethodName(applicationInterfaceMethod.getMethodName());
             applicationInterfaceMethodDataVO.setParameterType(applicationInterfaceMethod.getParameterType());
             applicationInterfaceMethodDataVO.setUri(applicationInterfaceMethod.getUri());
             applicationInterfaceMethodDataVO.setHttpCommandType(applicationInterfaceMethod.getHttpCommandType());
             applicationInterfaceMethodDataVO.setAuth(applicationInterfaceMethod.getAuth());
             applicationInterfaceMethodDataVOList.add(applicationInterfaceMethodDataVO);
         }
         return applicationInterfaceMethodDataVOList;
     }
 ​
     @Override
     public int queryApplicationInterfaceMethodListCountByPage(OperationRequest<ApplicationInterfaceMethodDataVO> request) {
         return applicationInterfaceMethodDao.queryApplicationInterfaceMethodListCountByPage(request);
     }
 ​
     @Override
     public List<GatewayServerDetaiDatalVO> queryGatewayServerDetailListByPage(OperationRequest<GatewayServerDetaiDatalVO> request) {
         List<GatewayServerDetail> applicationInterfaceMethods = gatewayServerDetailDao.queryGatewayServerDetailListByPage(request);
         List<GatewayServerDetaiDatalVO> gatewayServerDetailDataVOList = new ArrayList<>(applicationInterfaceMethods.size());
         for (GatewayServerDetail gatewayServerDetail : applicationInterfaceMethods) {
             GatewayServerDetaiDatalVO gatewayServerDetaiDatalVO = new GatewayServerDetaiDatalVO();
             gatewayServerDetaiDatalVO.setId(gatewayServerDetail.getId());
             gatewayServerDetaiDatalVO.setGroupId(gatewayServerDetail.getGroupId());
             gatewayServerDetaiDatalVO.setGatewayId(gatewayServerDetail.getGatewayId());
             gatewayServerDetaiDatalVO.setGatewayName(gatewayServerDetail.getGatewayName());
             gatewayServerDetaiDatalVO.setGatewayAddress(gatewayServerDetail.getGatewayAddress());
             gatewayServerDetaiDatalVO.setStatus(gatewayServerDetail.getStatus());
             gatewayServerDetaiDatalVO.setCreateTime(gatewayServerDetail.getCreateTime());
             gatewayServerDetaiDatalVO.setUpdateTime(gatewayServerDetail.getUpdateTime());
             gatewayServerDetailDataVOList.add(gatewayServerDetaiDatalVO);
         }
         return gatewayServerDetailDataVOList;
     }
 ​
     @Override
     public int queryGatewayServerDetailListCountByPage(OperationRequest<GatewayServerDetaiDatalVO> request) {
         return gatewayServerDetailDao.queryGatewayServerDetailListCountByPage(request);
     }
 ​
     @Override
     public List<GatewayDistributionDataVO> queryGatewayDistributionListByPage(OperationRequest<GatewayDistributionDataVO> request) {
         List<GatewayDistribution> gatewayDistributions = gatewayDistributionDao.queryGatewayDistributionListByPage(request);
         List<GatewayDistributionDataVO> gatewayServerDetailDataVOList = new ArrayList<>(gatewayDistributions.size());
         for (GatewayDistribution gatewayDistribution : gatewayDistributions) {
             GatewayDistributionDataVO gatewayDistributionDataVO = new GatewayDistributionDataVO();
             gatewayDistributionDataVO.setId(gatewayDistribution.getId());
             gatewayDistributionDataVO.setGroupId(gatewayDistribution.getGroupId());
             gatewayDistributionDataVO.setGatewayId(gatewayDistribution.getGatewayId());
             gatewayDistributionDataVO.setSystemId(gatewayDistribution.getSystemId());
             gatewayDistributionDataVO.setSystemName(gatewayDistribution.getSystemName());
             gatewayDistributionDataVO.setCreateTime(gatewayDistribution.getCreateTime());
             gatewayDistributionDataVO.setUpdateTime(gatewayDistribution.getUpdateTime());
             gatewayServerDetailDataVOList.add(gatewayDistributionDataVO);
         }
         return gatewayServerDetailDataVOList;
     }
 ​
     @Override
     public int queryGatewayDistributionListCountByPage(OperationRequest<GatewayDistributionDataVO> request) {
         return gatewayDistributionDao.queryGatewayDistributionListCountByPage(request);
     }
 }
 ​

最后是对应的sql语句

application_interface.xml

 <select id="queryApplicationInterfaceListByPage"
             parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest"
             resultMap="applicationInterfaceMap">
         SELECT id, system_id, interface_id, interface_name, interface_version
         FROM application_interface
         <where>
             <if test="data != null and data.systemId != ''">
                 and system_id = #{data.systemId}
             </if>
             <if test="data != null and data.interfaceId != ''">
                 and interface_id = #{data.interfaceId}
             </if>
         </where>
         order by id desc
         limit #{pageStart},#{pageEnd}
     </select>
 ​
     <select id="queryApplicationInterfaceListCountByPage"
             parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest"
             resultType="java.lang.Integer">
         SELECT count(id) FROM application_interface
         <where>
             <if test="data != null and data.systemId != ''">
                 and system_id = #{data.systemId}
             </if>
             <if test="data != null and data.interfaceId != ''">
                 and interface_id = #{data.interfaceId}
             </if>
         </where>
     </select>

application_interface_method.xml

 <select id="queryApplicationInterfaceMethodListByPage" parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest" resultMap="applicationInterfaceMethodMap">
         SELECT id, system_id, interface_id, method_id, method_name, parameter_type, uri, http_command_type, auth
         FROM application_interface_method
         <where>
             <if test="data != null and data.systemId != ''">
                 and system_id = #{data.systemId}
             </if>
             <if test="data != null and data.interfaceId != ''">
                 and interface_id = #{data.interfaceId}
             </if>
         </where>
         order by id desc
         limit #{pageStart},#{pageEnd}
     </select>
 ​
     <select id="queryApplicationInterfaceMethodListCountByPage"
             parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest"
             resultType="java.lang.Integer">
         SELECT count(id) FROM application_interface_method
         <where>
             <if test="data != null and data.systemId != ''">
                 and system_id = #{data.systemId}
             </if>
             <if test="data != null and data.interfaceId != ''">
                 and interface_id = #{data.interfaceId}
             </if>
         </where>
     </select>

application_system.xml

 <select id="queryApplicationSystemListByPage" parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest" resultMap="applicationSystemMap">
         SELECT id, system_id, system_name, system_type, system_registry
         FROM application_system
         <where>
             <if test="data != null and data.systemId != ''">
                 and system_id = #{data.systemId}
             </if>
             <if test="data != null and data.systemName != ''">
                 and system_name = #{data.systemName}
             </if>
         </where>
         order by id desc
         limit #{pageStart},#{pageEnd}
     </select>
 ​
     <select id="queryApplicationSystemListCountByPage" parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest" resultType="java.lang.Integer">
         SELECT count(id) FROM application_system
         <where>
             <if test="data != null and data.systemId != ''">
                 and system_id = #{data.systemId}
             </if>
             <if test="data != null and data.systemName != ''">
                 and system_name = #{data.systemName}
             </if>
         </where>
     </select>

gateway_distribution.xml

 <select id="queryGatewayDistributionListByPage"
             parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest"
             resultMap="gatewayDistributionMap">
         SELECT id, group_id, gateway_id, system_id, system_name, create_time, update_time
         FROM gateway_distribution
         <where>
             <if test="data != null and data.groupId != ''">
                 and group_id = #{data.groupId}
             </if>
             <if test="data != null and data.gatewayId != ''">
                 and gateway_id = #{data.gatewayId}
             </if>
         </where>
         order by id desc
         limit #{pageStart},#{pageEnd}
     </select>
 ​
     <select id="queryGatewayDistributionListCountByPage"
             parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest"
             resultType="java.lang.Integer">
         SELECT count(id) FROM gateway_distribution
         <where>
             <if test="data != null and data.groupId != ''">
                 and group_id = #{data.groupId}
             </if>
             <if test="data != null and data.gatewayId != ''">
                 and gateway_id = #{data.gatewayId}
             </if>
         </where>
     </select>

gateway_server.xml

 <select id="queryGatewayServerListByPage" parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest" resultMap="gatewayServerMap">
         SELECT id, group_id, group_name FROM gateway_server
         <where>
             <if test="null != data">
                 and group_id = #{data}
             </if>
         </where>
         order by id desc
         limit #{pageStart},#{pageEnd}
     </select>
 ​
     <select id="queryGatewayServerListCountByPage" parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest" resultType="java.lang.Integer">
         SELECT count(id) FROM gateway_server
         <where>
             <if test="null != data">
                 and group_id = #{data}
             </if>
         </where>
     </select>

gateway_server_detail.xml

 <select id="queryGatewayServerDetailListByPage"
             parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest"
             resultMap="gatewayServerDetailMap">
         SELECT id, group_id, gateway_id, gateway_name, gateway_address, status, create_time, update_time
         FROM gateway_server_detail
         <where>
             <if test="data != null and data.groupId != ''">
                 and group_id = #{data.groupId}
             </if>
             <if test="data != null and data.gatewayId != ''">
                 and gateway_id = #{data.gatewayId}
             </if>
         </where>
         order by id desc
         limit #{pageStart},#{pageEnd}
     </select>
 ​
     <select id="queryGatewayServerDetailListCountByPage"
             parameterType="com.zshunbao.gateway.center.infrastructure.common.OperationRequest"
             resultType="java.lang.Integer">
         SELECT count(id) FROM gateway_server_detail
         <where>
             <if test="data != null and data.groupId != ''">
                 and group_id = #{data.groupId}
             </if>
             <if test="data != null and data.gatewayId != ''">
                 and gateway_id = #{data.gatewayId}
             </if>
         </where>
     </select>

到此功能代码全部完成

测试

  • 启动api-gateway-center项目

  • 启动api-gateway-admin前端项目

测试成功,前端成功拿到后端数据

参考资料