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