文档完善和逻辑优化
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
package com.zyplayer.doc.manage.repository.support.plus.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.entity.ZyplayerStorage;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
public interface ZyplayerStorageMapper extends BaseMapper<ZyplayerStorage> {
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.zyplayer.doc.manage.repository.support.plus.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.entity.ZyplayerStorage;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
public interface ZyplayerStorageMapper extends BaseMapper<ZyplayerStorage> {
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.zyplayer.doc.manage.repository.support.plus.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
public class ZyplayerStorage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String docKey;
|
||||
|
||||
private String docValue;
|
||||
|
||||
private Date creationTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getDocKey() {
|
||||
return docKey;
|
||||
}
|
||||
|
||||
public void setDocKey(String docKey) {
|
||||
this.docKey = docKey;
|
||||
}
|
||||
public String getDocValue() {
|
||||
return docValue;
|
||||
}
|
||||
|
||||
public void setDocValue(String docValue) {
|
||||
this.docValue = docValue;
|
||||
}
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ZyplayerStorage{" +
|
||||
"id=" + id +
|
||||
", docKey=" + docKey +
|
||||
", docValue=" + docValue +
|
||||
", creationTime=" + creationTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.zyplayer.doc.manage.repository.support.plus.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
public class ZyplayerStorage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String docKey;
|
||||
|
||||
private String docValue;
|
||||
|
||||
private Date creationTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getDocKey() {
|
||||
return docKey;
|
||||
}
|
||||
|
||||
public void setDocKey(String docKey) {
|
||||
this.docKey = docKey;
|
||||
}
|
||||
public String getDocValue() {
|
||||
return docValue;
|
||||
}
|
||||
|
||||
public void setDocValue(String docValue) {
|
||||
this.docValue = docValue;
|
||||
}
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ZyplayerStorage{" +
|
||||
"id=" + id +
|
||||
", docKey=" + docKey +
|
||||
", docValue=" + docValue +
|
||||
", creationTime=" + creationTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.zyplayer.doc.manage.repository.support.plus.manage.service;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.entity.ZyplayerStorage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
public interface ZyplayerStorageService extends IService<ZyplayerStorage> {
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.zyplayer.doc.manage.repository.support.plus.manage.service;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.entity.ZyplayerStorage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
public interface ZyplayerStorageService extends IService<ZyplayerStorage> {
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.zyplayer.doc.manage.repository.support.plus.manage.service.impl;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.entity.ZyplayerStorage;
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.mapper.ZyplayerStorageMapper;
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.service.ZyplayerStorageService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
@Service
|
||||
public class ZyplayerStorageServiceImpl extends ServiceImpl<ZyplayerStorageMapper, ZyplayerStorage> implements ZyplayerStorageService {
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.zyplayer.doc.manage.repository.support.plus.manage.service.impl;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.entity.ZyplayerStorage;
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.mapper.ZyplayerStorageMapper;
|
||||
import com.zyplayer.doc.manage.repository.support.plus.manage.service.ZyplayerStorageService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
@Service
|
||||
public class ZyplayerStorageServiceImpl extends ServiceImpl<ZyplayerStorageMapper, ZyplayerStorage> implements ZyplayerStorageService {
|
||||
|
||||
}
|
||||
@@ -1,19 +1,24 @@
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import org.springframework.boot.web.server.ErrorPage;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@Configuration
|
||||
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableServletWebServerFactory factory) {
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/statics/common/403.html"));
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/statics/common/404.html"));
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/statics/common/500.html"));
|
||||
}
|
||||
|
||||
}
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import org.springframework.boot.web.server.ErrorPage;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* 自定义错误页面
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年11月11日
|
||||
*/
|
||||
@Configuration
|
||||
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableServletWebServerFactory factory) {
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/statics/common/403.html"));
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/statics/common/404.html"));
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/statics/common/500.html"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.ZyplayerStorage;
|
||||
import com.zyplayer.doc.manage.service.manage.ZyplayerStorageService;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorage;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||
|
||||
/**
|
||||
* 申明为@Service之后网页上才能使用存储能力,同时需要在@EnableSwagger2的地方添加@EnableSwaggerMgUi注解,
|
||||
* 才能开启存储的接口<br/>
|
||||
* 开放存储能力的好处:<br/>
|
||||
* 所有网页的配置、调试值都可以存储到服务器的数据库中,便于团队所有人的调试,一人配置,所有人受益<br/>
|
||||
* 如果不开启的话,数据是存放在浏览器的localStorage中,每个人、每个浏览器都得配置一次才能使用<br/>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月19日
|
||||
*/
|
||||
@Service
|
||||
public class MgStorageServiceImpl implements MgStorageService {
|
||||
|
||||
@Autowired
|
||||
ZyplayerStorageService zyplayerStorageService;
|
||||
|
||||
/**
|
||||
* 使用数据库来存储,例: storageMapper.select(key);
|
||||
*/
|
||||
@Override
|
||||
public String get(String key) {
|
||||
QueryWrapper<ZyplayerStorage> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("doc_key", key);
|
||||
ZyplayerStorage zyplayerStorage = zyplayerStorageService.getOne(wrapper);
|
||||
if (zyplayerStorage == null) {
|
||||
return null;
|
||||
}
|
||||
return zyplayerStorage.getDocValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MgStorage> like(String key, String value) {
|
||||
QueryWrapper<ZyplayerStorage> wrapper = new QueryWrapper<>();
|
||||
wrapper.like(StringUtils.isNotBlank(key), "doc_key", key);
|
||||
wrapper.like(StringUtils.isNotBlank(value), "doc_value", value);
|
||||
List<ZyplayerStorage> storageList = zyplayerStorageService.list(wrapper);
|
||||
if (storageList == null || storageList.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<MgStorage> resultList = storageList.stream().map(val -> {
|
||||
return new MgStorage(val.getDocKey(), val.getDocValue());
|
||||
}).collect(Collectors.toList());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用数据库来存储,例: storageMapper.updateOrInsert(key, value);
|
||||
*/
|
||||
@Override
|
||||
public void put(String key, String value) {
|
||||
ZyplayerStorage entity = new ZyplayerStorage();
|
||||
entity.setDocValue(value);
|
||||
UpdateWrapper<ZyplayerStorage> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq(true, "doc_key", key);
|
||||
boolean update = zyplayerStorageService.update(entity, updateWrapper);
|
||||
if (!update) {
|
||||
entity = new ZyplayerStorage();
|
||||
entity.setDocValue(value);
|
||||
entity.setDocKey(key);
|
||||
zyplayerStorageService.save(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个key
|
||||
*/
|
||||
@Override
|
||||
public void remove(String key) {
|
||||
UpdateWrapper<ZyplayerStorage> queryWrapper = new UpdateWrapper<>();
|
||||
queryWrapper.eq(true, "doc_key", key);
|
||||
zyplayerStorageService.remove(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.ZyplayerStorage;
|
||||
import com.zyplayer.doc.manage.service.manage.ZyplayerStorageService;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorage;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||
|
||||
/**
|
||||
* 申明为@Service之后网页上才能使用存储能力,同时需要在@EnableSwagger2的地方添加@EnableSwaggerMgUi注解,
|
||||
* 才能开启存储的接口<br/>
|
||||
* 开放存储能力的好处:<br/>
|
||||
* 所有网页的配置、调试值都可以存储到服务器的数据库中,便于团队所有人的调试,一人配置,所有人受益<br/>
|
||||
* 如果不开启的话,数据是存放在浏览器的localStorage中,每个人、每个浏览器都得配置一次才能使用<br/>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月19日
|
||||
*/
|
||||
@Service
|
||||
public class MgStorageServiceImpl implements MgStorageService {
|
||||
|
||||
@Autowired
|
||||
ZyplayerStorageService zyplayerStorageService;
|
||||
|
||||
/**
|
||||
* 使用数据库来存储,例: storageMapper.select(key);
|
||||
*/
|
||||
@Override
|
||||
public String get(String key) {
|
||||
QueryWrapper<ZyplayerStorage> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("doc_key", key);
|
||||
ZyplayerStorage zyplayerStorage = zyplayerStorageService.getOne(wrapper);
|
||||
if (zyplayerStorage == null) {
|
||||
return null;
|
||||
}
|
||||
return zyplayerStorage.getDocValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MgStorage> like(String key, String value) {
|
||||
QueryWrapper<ZyplayerStorage> wrapper = new QueryWrapper<>();
|
||||
wrapper.like(StringUtils.isNotBlank(key), "doc_key", key);
|
||||
wrapper.like(StringUtils.isNotBlank(value), "doc_value", value);
|
||||
List<ZyplayerStorage> storageList = zyplayerStorageService.list(wrapper);
|
||||
if (storageList == null || storageList.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<MgStorage> resultList = storageList.stream().map(val -> {
|
||||
return new MgStorage(val.getDocKey(), val.getDocValue());
|
||||
}).collect(Collectors.toList());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用数据库来存储,例: storageMapper.updateOrInsert(key, value);
|
||||
*/
|
||||
@Override
|
||||
public void put(String key, String value) {
|
||||
ZyplayerStorage entity = new ZyplayerStorage();
|
||||
entity.setDocValue(value);
|
||||
UpdateWrapper<ZyplayerStorage> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq(true, "doc_key", key);
|
||||
boolean update = zyplayerStorageService.update(entity, updateWrapper);
|
||||
if (!update) {
|
||||
entity = new ZyplayerStorage();
|
||||
entity.setDocValue(value);
|
||||
entity.setDocKey(key);
|
||||
zyplayerStorageService.save(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个key
|
||||
*/
|
||||
@Override
|
||||
public void remove(String key) {
|
||||
UpdateWrapper<ZyplayerStorage> queryWrapper = new UpdateWrapper<>();
|
||||
queryWrapper.eq("doc_key", key);
|
||||
zyplayerStorageService.remove(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
package com.zyplayer.doc.swagger.framework.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||
|
||||
/**
|
||||
* 有需要此拦截器的请自行拷贝至自身项目,不再开启@Component<br>
|
||||
* 判断是否是模拟请求,功能需求:<br>
|
||||
* 很多时候后端定义好了接口,但还未实现,这时前端已经需要数据调试了,这时就需要用到这个过滤器了!<br>
|
||||
* 在页面上先配置好模拟返回的数据,然后在url上加入参数:mgUiTestFlag=1<br>
|
||||
* 例:http://192.168.0.249:8082/openApi/case/info?mgUiTestFlag=1<br>
|
||||
* 本过滤器就直接返回了之前配置的模拟数据,而不用等到后端必须把接口实现之后才能调试,或者在前端写一大段测试数据。<br>
|
||||
*
|
||||
* 例:笔者的公司后端人较少,一个需求需要10个接口,需求分析完后首先就把接口、参数、返回值定义好,然后一个个的去实现。
|
||||
* 也许需要10天才能写完,但前端两天就写好了,急需数据看效果,这时就让他们自己去设置模拟值,加上参数自己测试好。
|
||||
* 而不是一味的催后台,把各种锅丢给后端,然后玩自己的去了,浪费各环节等待时间。
|
||||
*/
|
||||
//@Component
|
||||
public class MgUiTestFilter implements Filter {
|
||||
|
||||
@Autowired(required = false)
|
||||
private MgStorageService mgStorageService;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
String mockTestFlag = request.getParameter("mgUiTestFlag");
|
||||
if (!"1".equals(mockTestFlag)) {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
// 如果是模拟请求则直接返回模拟值
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||
String requestUrl = httpServletRequest.getRequestURI();
|
||||
String cacheResult = mgStorageService.get("p-simulation-response-" + requestUrl);
|
||||
if (cacheResult != null) {
|
||||
responseWrite(cacheResult, (HttpServletResponse) response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
private static void responseWrite(String params, HttpServletResponse response) throws IOException {
|
||||
response.setStatus(200);
|
||||
// response.setContentType("application/json");
|
||||
// 模拟返回支持跨域访问,正式对接需要自己协调怎么处理跨域问题
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setContentType("text/html");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Cache-Control", "no-cache, must-revalidate");
|
||||
response.getWriter().write(params);
|
||||
}
|
||||
|
||||
}
|
||||
package com.zyplayer.doc.swagger.framework.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||
|
||||
/**
|
||||
* 有需要此拦截器的请自行拷贝至自身项目,需要使过滤器生效,文档不再开启@Component<br>
|
||||
* 判断是否是模拟请求,功能需求:<br>
|
||||
* 很多时候后端定义好了接口,但还未实现,这时前端已经需要数据调试了,这时就需要用到这个过滤器了!<br>
|
||||
* 在页面上先配置好模拟返回的数据,然后在url上加入参数:mgUiTestFlag=1<br>
|
||||
* 例:http://192.168.0.249:8082/openApi/case/info?mgUiTestFlag=1<br>
|
||||
* 本过滤器就直接返回了之前配置的模拟数据,而不用等到后端必须把接口实现之后才能调试,或者在前端写一大段测试数据。<br>
|
||||
* <p>
|
||||
* 例:笔者的公司后端人较少,一个需求需要10个接口,需求分析完后首先就把接口、参数、返回值定义好,然后一个个的去实现。
|
||||
* 也许需要10天才能写完,但前端两天就写好了,急需数据看效果,这时就让他们自己去设置模拟值,加上参数自己测试好。
|
||||
* 而不是一味的催后台,把各种锅丢给后端,然后玩自己的去了,浪费各环节等待时间。
|
||||
*/
|
||||
//@Component
|
||||
public class MgUiTestFilter implements Filter {
|
||||
|
||||
@Autowired
|
||||
private MgStorageService mgStorageService;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
// 需要使用模拟值返回的标记
|
||||
String mockTestFlag = request.getParameter("mgUiTestFlag");
|
||||
if (!"1".equals(mockTestFlag)) {
|
||||
// 未开启直接跳过
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
// 如果是模拟请求则直接返回模拟值
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||
String requestUrl = httpServletRequest.getRequestURI();
|
||||
// 文档页面存,这里取,就这么简单。。。
|
||||
// 存取位置和文档的一致,"p-simulation-response-" + requestUrl 不能修改,因为存就是这样存的
|
||||
String cacheResult = mgStorageService.get("p-simulation-response-" + requestUrl);
|
||||
if (cacheResult != null) {
|
||||
HttpServletResponse servletResponse = (HttpServletResponse) response;
|
||||
servletResponse.setStatus(200);
|
||||
// response.setContentType("application/json");
|
||||
// 模拟返回支持跨域访问,正式对接需要自己协调怎么处理跨域问题
|
||||
servletResponse.addHeader("Access-Control-Allow-Origin", "*");
|
||||
servletResponse.setContentType("text/html");
|
||||
servletResponse.setCharacterEncoding("UTF-8");
|
||||
servletResponse.setHeader("Cache-Control", "no-cache, must-revalidate");
|
||||
servletResponse.getWriter().write(cacheResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -297,13 +297,21 @@
|
||||
</div>
|
||||
<div class="tab-pane tab-document-pane" id="tabSimulationResult">
|
||||
<table class="table table-bordered doc-table">
|
||||
<tr>
|
||||
<td class="info">功能说明</td>
|
||||
<td>
|
||||
访问接口时增加参数:mgUiTestFlag=1,即可返回下面提交的模拟返回值<br/>
|
||||
需要被访问项目增加<a href="https://gitee.com/zyplayer/zyplayer-doc/blob/master/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/framework/filter/MgUiTestFilter.java" target="_blank"> MgUiTestFilter.java</a>
|
||||
过滤器才能使用,里面逻辑很简单,一看就懂~
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="info">接口地址</td>
|
||||
<td><span id="simulationResultUrl" class="label label-warning"></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="info">测试地址</td>
|
||||
<td><a id="simulationResultUrlTest" href="" target="_blank"></a> <i class="icon icon-info-sign" title='需要被访问项目导入zyplayer-doc包才能使用'></i></td>
|
||||
<td><a id="simulationResultUrlTest" href="" target="_blank"></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="info">返回内容</td>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* 页面中所有使用到的缓存key必须定义在这里
|
||||
*/
|
||||
var cacheKeys = {
|
||||
userSettings: 'userSettings',
|
||||
swaggerResourcesList: 'swagger-resources-list',
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* 所有需要iframe页面调用的接口必须定义在这里
|
||||
* 通过getExport()来吊起父页面的这些接口
|
||||
*/
|
||||
var exports = {
|
||||
regeneratePathTree: function(){
|
||||
// 定义在mg-ui.js,用于重新生成文档树目录
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* zyplayer-doc-swagger是swagger-ui的一个前端实现,使用简单、解析速度快、走心的设计
|
||||
* zyplayer-doc-swagger是swagger的一个前端实现,使用简单、解析速度快、走心的设计
|
||||
* 支持多项目同时展示,多种文档目录的展示方案,多种自定义配置,满足各种使用习惯。
|
||||
* 使用中您有任何的意见和建议都可到源码地址处反馈哦!
|
||||
* git地址:https://gitee.com/zyplayer/zyplayer-doc-swagger
|
||||
* git地址:https://gitee.com/zyplayer/zyplayer-doc
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年5月20日
|
||||
*/
|
||||
@@ -35,20 +35,8 @@ var defaultUserSettings = {
|
||||
prevWNow : 360
|
||||
};
|
||||
|
||||
var swaggerApiDocsArr = [];
|
||||
|
||||
var requestParamObj = {};
|
||||
// 模板示例
|
||||
var requestParamObjTemp = {
|
||||
taskId: {
|
||||
value: 1,// 参数值
|
||||
paramType: 'string',// 参数类型,string int boolean
|
||||
required: true,// 是否必填
|
||||
paramIn: 'body',// 参数位置,body query header
|
||||
paramDesc: '参数说明'
|
||||
}
|
||||
};
|
||||
|
||||
// 文档管理的tables
|
||||
var rightContentTabs;
|
||||
|
||||
/**
|
||||
@@ -169,6 +157,7 @@ $("#searchDocInput").keyup(function(e) {
|
||||
searchDoc();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 搜索按钮点击
|
||||
*/
|
||||
@@ -177,7 +166,7 @@ $("#searchDocBt").click(function(){
|
||||
});
|
||||
|
||||
/**
|
||||
* 导出文档
|
||||
* 导出文档-子页面调用-文档地址管理
|
||||
*/
|
||||
function exportDocument(){
|
||||
// 清空
|
||||
@@ -195,6 +184,9 @@ function exportDocument(){
|
||||
$('#exportDocumentModal').modal('ajustPosition', 'fit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认导出
|
||||
*/
|
||||
$("#doExportBtn").click(function(){
|
||||
var jsonStrAll = "";
|
||||
var mgUiDataArr = "var mgUiDataArr = [";
|
||||
@@ -268,22 +260,6 @@ $("#choiseDocBtn").click(function(){
|
||||
$('#choiseDocModal').modal('hide');
|
||||
});
|
||||
|
||||
/**
|
||||
* 增加文档的保存按钮
|
||||
*/
|
||||
$("#addNewDocumentBtn").click(function(){
|
||||
var addNewDocumentInput = $("#addNewDocumentInput").val();
|
||||
if(isEmpty(addNewDocumentInput)) {
|
||||
Toast.error("地址不可以为空");return;
|
||||
}
|
||||
projectLoadingIndex = 1;
|
||||
ajaxTemp("swagger-mg-ui/document/addSwaggerResources", "post", "json", {resourcesUrl: addNewDocumentInput}, function(json){
|
||||
if(validateResult(json)) {
|
||||
document.location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 主页li点击事件,展示主页
|
||||
*/
|
||||
@@ -578,7 +554,10 @@ function searchDoc() {
|
||||
// }
|
||||
}
|
||||
|
||||
// 重新生成文档
|
||||
/**
|
||||
* 重新生成文档
|
||||
*/
|
||||
|
||||
function regeneratePathTree(keywords){
|
||||
projectTreeIdIndex = 1;
|
||||
treePathDataMap = new Map();
|
||||
@@ -909,39 +888,7 @@ function documentLoadFinish() {
|
||||
globalLoadingMessager.hide();
|
||||
}, 1000);
|
||||
$('#apiPathTree .projects').tree();
|
||||
$('#homePageDashboard').dashboard({draggable: false,
|
||||
// 修改排序
|
||||
afterOrdered:function(newOrders){
|
||||
/*//console.log(newOrders);
|
||||
var tempProjects = [], nowIndex = 0, settingTableIndex = 1;
|
||||
Object.keys(newOrders).forEach(function(key){
|
||||
if(key == 1) {
|
||||
settingTableIndex = newOrders[key];
|
||||
return;
|
||||
}
|
||||
var subCount = (newOrders[key] > settingTableIndex) ? 2 : 1;
|
||||
tempProjects[newOrders[key] - subCount] = key;
|
||||
});
|
||||
userSettings.projects = tempProjects;
|
||||
storeUserSettings();
|
||||
*/
|
||||
// 应该是控件问题,拖动之后单选项被值空了,需要重新设置选中,而且还必须等一会设置才有效果。。
|
||||
setTimeout("updateUserSettingsUi();", 500);
|
||||
},
|
||||
// 修改大小
|
||||
onResize:function(){
|
||||
|
||||
},
|
||||
// 被移除
|
||||
afterPanelRemoved:function(id){
|
||||
//console.log(id);
|
||||
ajaxTemp("swagger-mg-ui/document/deleteSwaggerDoc", "post", "json", {docUrl: id}, function(json){
|
||||
if(validateResult(json)) {
|
||||
document.location.reload();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
$('#homePageDashboard').dashboard({draggable: false});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
/**
|
||||
* 提示工具类
|
||||
* @author 暮光:城中城
|
||||
* @since 2017年5月7日
|
||||
*/
|
||||
var Toast = {
|
||||
notOpen:function(){
|
||||
var data = {
|
||||
message:"该功能暂未开放,敬请期待!",
|
||||
icon: 'exclamation-sign',type:"warning",
|
||||
};
|
||||
this.show(data);
|
||||
},
|
||||
success:function(msg, time){
|
||||
var data = {
|
||||
message:msg,time:time,
|
||||
icon: 'check-circle-o',type:'success',
|
||||
};
|
||||
this.show(data);
|
||||
},
|
||||
warn:function(msg, time){
|
||||
var data = {
|
||||
message:msg,time:time,
|
||||
icon: 'exclamation-sign',type:'warning',
|
||||
};
|
||||
this.show(data);
|
||||
},
|
||||
error:function(msg, time){
|
||||
var data = {
|
||||
message:msg,time:time,
|
||||
icon: 'exclamation-sign',type:'danger',
|
||||
};
|
||||
this.show(data);
|
||||
},
|
||||
show:function(data){
|
||||
data.time = isEmpty(data.time)?2000:data.time;
|
||||
data.placement = isEmpty(data.placement)?'top':data.placement;
|
||||
new $.zui.Messager(data.message, data).show();
|
||||
}
|
||||
/**
|
||||
* 提示工具类
|
||||
* @author 暮光:城中城
|
||||
* @since 2017年5月7日
|
||||
*/
|
||||
var Toast = {
|
||||
notOpen: function () {
|
||||
var data = {
|
||||
message: "该功能暂未开放,敬请期待!",
|
||||
icon: 'exclamation-sign', type: "warning",
|
||||
};
|
||||
this.show(data);
|
||||
},
|
||||
success: function (msg, time) {
|
||||
var data = {
|
||||
message: msg, time: time,
|
||||
icon: 'check-circle-o', type: 'success',
|
||||
};
|
||||
this.show(data);
|
||||
},
|
||||
warn: function (msg, time) {
|
||||
var data = {
|
||||
message: msg, time: time,
|
||||
icon: 'exclamation-sign', type: 'warning',
|
||||
};
|
||||
this.show(data);
|
||||
},
|
||||
error: function (msg, time) {
|
||||
var data = {
|
||||
message: msg, time: time,
|
||||
icon: 'exclamation-sign', type: 'danger',
|
||||
};
|
||||
this.show(data);
|
||||
},
|
||||
show: function (data) {
|
||||
data.time = isEmpty(data.time) ? 2000 : data.time;
|
||||
data.placement = isEmpty(data.placement) ? 'top' : data.placement;
|
||||
new $.zui.Messager(data.message, data).show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user