关联数据分离mock测试
【摘要】 关联数据分离mock测试
好脾气是一个人在社交中所能穿着的最佳服饰。——都德
QucikStart
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
box-sizing: border-box;
}
body {
font: 16px Arial;
}
.autocomplete {
/*容器定位设置为 relative:*/
position: relative;
display: inline-block;
}
input {
border: 1px solid transparent;
background-color: #f1f1f1;
padding: 10px;
font-size: 16px;
}
input[type=text] {
background-color: #f1f1f1;
width: 100%;
}
input[type=submit] {
background-color: DodgerBlue;
color: #fff;
}
.autocomplete-items {
position: absolute;
border: 1px solid #d4d4d4;
border-bottom: none;
border-top: none;
z-index: 99;
/*设置自动填充项宽度与容器相同*/
top: 100%;
left: 0;
right: 0;
}
.autocomplete-items div {
padding: 10px;
cursor: pointer;
background-color: #fff;
border-bottom: 1px solid #d4d4d4;
}
.autocomplete-items div:hover {
/*鼠标移动到填充项设置的背景颜色*/
background-color: #e9e9e9;
}
.autocomplete-active {
/*使用箭头键浏览填充项时的背景颜色*/
background-color: DodgerBlue !important;
color: #ffffff;
}
</style>
</head>
<body>
<!-- autocomplete="off" 确保表单已关闭自动填充功能: -->
<form autocomplete="off" action="/index.php">
<div class="autocomplete" style="width:300px;">
<input id="myInput" type="text" name="s" placeholder="请输入搜索内容">
</div>
</form>
<script type="text/javascript">
const sites = [{ "key": "evacuationZoneRepository", "value": "1533998933871693824" }, { "key": "broadcastAudioRepository", "value": "1523607377289416704" }, { "key": "educatePageLimitRepository", "value": "1557614724332392448" }, { "key": "userExpandRepository", "value": "1559810341049733120" }, { "key": "locationBeaconRepository", "value": "1559725301682933760" }, { "key": "dictionariesRepository", "value": "1" }, { "key": "riskWarnRepository", "value": "1562261534883713043" }, { "key": "hiddenTaskRepository", "value": "1592344560070037504" }, { "key": "testPaperRepository", "value": "1548972953230643200" }, { "key": "broadcastRepository", "value": "null" }, { "key": "educatePageCarouselRepository", "value": "1554739986987749376" }, { "key": "questionDeviceRepository", "value": "1540264017098969088" }, { "key": "trainLogRepository", "value": "1561548612448555008" }, { "key": "riskPointRepository", "value": "1590227432663683072" }, { "key": "workAreaRepository", "value": "1561953948250673152" }, { "key": "operationProcessMaturityRepository", "value": "1552140582934024192" }, { "key": "operationArchiveSpecialPAppendRepository", "value": "1544137372092862464" }, { "key": "operationProcessWeatherRepository", "value": "1558358009208377344" }, { "key": "DCMajorDangerSourceIdentifyRepository", "value": "1587005703132811264" }, { "key": "hideFlowConfirmRepository", "value": "1590290098941197476" }, { "key": "t03TicketRepository", "value": "1559790526452994048" }, { "key": "checkContentsRepository", "value": "1555749605012934656" }, { "key": "operationAreaRepository", "value": "1559782500870393856" }, { "key": "alarmTypeRepository", "value": "null" }, { "key": "iconRepository", "value": "null" }, { "key": "keyAlarmRepository", "value": "1559706575508082688" }, { "key": "warningMessageRepository", "value": "1567059992870129664" }, { "key": "rulesRiskJudgmentRepository", "value": "1590177806891880448" }, { "key": "operationProcessEnvRepository", "value": "1548849318851514368" }, { "key": "rulesRiskControlRepository", "value": "1590540040142852096" }, { "key": "hidePerformanceDetailRepository", "value": "1593432704030871552" }, { "key": "t01TicketRepository", "value": "1559782523033096192" }, { "key": "t04TicketRepository", "value": "1559447218295934976" }, { "key": "checkRouteRepository", "value": "1553316053604372480" }, { "key": "personnelStatisticsRepository", "value": "null" }, { "key": "questionAnswerRepository", "value": "1552491804442497024" }, { "key": "abnormalConfigureRepository", "value": "1" }, { "key": "operationDataTypeOfWorkRepository", "value": "1544139417206132736" }, { "key": "hideFlowExtensionRepository", "value": "1590290092948197579" }, { "key": "checkAlarmRepository", "value": "1559459071076077568" }, { "key": "securitySignatureRepository", "value": "1546705892630597632" }, { "key": "accidentSpotRepository", "value": "1533999512287186944" }, { "key": "judgmentCriteriaRepository", "value": "1593435857417670656" }, { "key": "questionRepository", "value": "1547428406730166272" }, { "key": "t06TicketRepository", "value": "1559711498786312192" }, { "key": "departmentRepository", "value": "1522097758020833280" }, { "key": "rehearsalPlanRepository", "value": "1534070295248244736" }, { "key": "hiddenPlanRepository", "value": "1590954883823964160" }, { "key": "keyAlarmRuleRepository", "value": "1560171749402742784" }, { "key": "controlTypeRepository", "value": "1585104834338492416" }, { "key": "keyAlarmLogRepository", "value": "1559120241886236672" }, { "key": "analysePlanRepository", "value": "1590222770426351616" }, { "key": "videoRepository", "value": "null" }, { "key": "operationDataGasRepository", "value": "1546424890830098432" }, { "key": "hideScreeningMgtRepository", "value": "1590290115849097316" }, { "key": "questionClassifyRepository", "value": "1547426924920311808" }, { "key": "inspectionProjectRepository", "value": "1554302648704831488" }, { "key": "operationTicketRepository", "value": "1559781536029478912" }, { "key": "inspectionRepository", "value": "1553315607124905984" }, { "key": "hideFlowVerificationRepository", "value": "1593134860229152769" }, { "key": "riskEvaluateRepository", "value": "1590251457607634944" }, { "key": "systemRiskAuditorsRepository", "value": "1590162053258022912" }, { "key": "carRepository", "value": "null" }, { "key": "inspectionReviewRepository", "value": "1539510535635079168" }, { "key": "hideFlowUpRepository", "value": "1590290090948197476" }, { "key": "trainPlanRepository", "value": "1561539171397406720" }, { "key": "hideFlowChangeRepository", "value": "1590290092948197376" }, { "key": "postRepository", "value": "1516330277993975808" }, { "key": "securityMeasureRepository", "value": "1555402985754857472" }, { "key": "visitorRepository", "value": "null" }, { "key": "educatePageNewsRepository", "value": "1557617828062826496" }, { "key": "rulesRiskConfirmRepository", "value": "1590180326091526144" }, { "key": "patRepository", "value": "1561253829721198592" }, { "key": "patResponsibleRepository", "value": "1537678344751943680" }, { "key": "rulesRiskDivisionRepository", "value": "1590179045868310528" }, { "key": "permissionRepository", "value": "1564192021944471552" }, { "key": "locationTagRepository", "value": "1531819413899055116" }, { "key": "abnormalDisposeRepository", "value": "1560097738375303168" }, { "key": "t08TicketRepository", "value": "1560105460047024128" }, { "key": "locationFenceRuleRepository", "value": "1535513634623459328" }, { "key": "operationDataMoveGasRepository", "value": "1554633921856016384" }, { "key": "evaluationMethodRepository", "value": "1585823100509884416" }, { "key": "taskCheckListRepository", "value": "1592344560267169792" }, { "key": "operationProcessTimeOutRepository", "value": "1544544800244502528" }, { "key": "gasAnalyseRepository", "value": "1545294748758052864" }, { "key": "inspectionTypeRepository", "value": "1553269224263127040" }, { "key": "operationDataMoveCameraRepository", "value": "1554634153205436416" }, { "key": "workflowRepository", "value": "1556542782733029376" }, { "key": "checkpointsRepository", "value": "1557262068514557952" }, { "key": "operationDataTypeRepository", "value": "1543846869229113344" }, { "key": "controlMeasuresRepository", "value": "1585160567369240576" }, { "key": "inspectionPlanRepository", "value": "1559722369268846592" }, { "key": "judgmentStandardRepository", "value": "1587716815100841984" }, { "key": "educatePageBulletinRepository", "value": "1557293242960056320" }, { "key": "districtRepository", "value": "null" }, { "key": "locationAlarmRuleRepository", "value": "1534445293032968192" }, { "key": "operationDataGasTypeRepository", "value": "1544618818955907072" }, { "key": "locationFenceRepository", "value": "1564810360450453504" }, { "key": "operationTemplateRepository", "value": "1544241173797801984" }, { "key": "operationWarningLogRepository", "value": "1552138199202009088" }, { "key": "educateMaterialRepository", "value": "1549296486062231552" }, { "key": "examUserRepository", "value": "1549659632396406784" }, { "key": "systemFacilitiesRepository", "value": "1590165097966211072" }, { "key": "rehearsalPlanLogRepository", "value": "1534483005974777856" }, { "key": "operationArchiveSpecialPRepository", "value": "1564551167436918784" }, { "key": "hideFlowDownRepository", "value": "1594606267152732160" }, { "key": "securityMeasureDataRepository", "value": "1561199811040907264" }, { "key": "t02TicketRepository", "value": "1560445204270419968" }, { "key": "riskAnalyseRepository", "value": "1590237240288612352" }, { "key": "riskAuditLogRepository", "value": "1590229915901366272" }, { "key": "dangerSourceRepository", "value": "1590251269279191040" }, { "key": "userRepository", "value": "1556462851168669696" }, { "key": "systemDangerousChemicalsRepository", "value": "1590168577531449344" }, { "key": "t07TicketRepository", "value": "1559711979281584128" }, { "key": "signInRuleRepository", "value": "1559455940569206784" }, { "key": "locationFenceAlarmRepository", "value": "1534459118956318720" }, { "key": "t05TicketRepository", "value": "1560534837494812672" }];
function autocomplete(inp, arr) {
/*自动填充函数有两个参数,input 输入框元素和自动填充的数组*/
let currentFocus;
/* 监听 input 输入框,当在 input 输入框元素中时执行以下函数*/
inp.addEventListener("input", function (e) {
let a, b, i, val = this.value;
/*关闭已打开的自动填充列表*/
closeAllLists();
if (!val) { return false; }
currentFocus = -1;
/*创建 DIV 元素用于放置自动填充列表的值*/
a = document.createElement("DIV");
a.setAttribute("id", this.id + "autocomplete-list");
a.setAttribute("class", "autocomplete-items");
/*DIV 作为自动填充容器的子元素*/
this.parentNode.appendChild(a);
/*循环数组*/
for (i = 0; i < arr.length; i++) {
const key = arr[i].key;
const value = arr[i].value;
/*检查填充项是否有与文本字段值相同的内容,不区分大小写*/
if (key.substr(0, val.length).toUpperCase() == val.toUpperCase()) {
/*为每个匹配元素创建一个 DIV 元素 */
b = document.createElement("DIV");
/*匹配项加粗*/
b.innerHTML = "<strong>" + key.substr(0, val.length) + "</strong>";
b.innerHTML += key.substr(val.length);
/*选中的填充项插入到隐藏 input 输入字段,用于保存当前选中值*/
b.innerHTML += "<input type='hidden' value='" + value + "'>";
/*当有人点击填充项(DIV 元素)时执行函数*/
b.addEventListener("click", function (e) {
/*选中的填充项插入到隐藏 input 搜索字段*/
inp.value = this.getElementsByTagName("input")[0].value;
/*关闭自动填充列表*/
closeAllLists();
});
a.appendChild(b);
}
}
});
/*按下键盘上的一个键时执行函数*/
inp.addEventListener("keydown", function (e) {
let x = document.getElementById(this.id + "autocomplete-list");
if (x) x = x.getElementsByTagName("div");
if (e.keyCode == 40) {
/*如果按下箭头向下键,currentFocus 变量加 1,即向下移动一位*/
currentFocus++;
/*使当前选中项更醒目*/
addActive(x);
} else if (e.keyCode == 38) { //up
/*按下箭头向上键,选中列表项向上移动一位*/
currentFocus--;
/*使当前选中项更醒目*/
addActive(x);
} else if (e.keyCode == 13) {
/*如果按下 ENTER 键,阻止提交,你也可以设置 submit 提交*/
e.preventDefault();
if (currentFocus > -1) {
/*模拟点击选中项*/
if (x) x[currentFocus].click();
}
}
});
function addActive(x) {
/*设置选中的选项函数*/
if (!x) return false;
/*移动选项设置不同选中选项的背景颜色*/
removeActive(x);
if (currentFocus >= x.length) currentFocus = 0;
if (currentFocus < 0) currentFocus = (x.length - 1);
/*添加 "autocomplete-active" 类*/
x[currentFocus].classList.add("autocomplete-active");
}
function removeActive(x) {
/*移除没有选中选项的 "autocomplete-active" 类*/
for (let i = 0; i < x.length; i++) {
x[i].classList.remove("autocomplete-active");
}
}
function closeAllLists(elmnt) {
/*关闭自动添加列表*/
let x = document.getElementsByClassName("autocomplete-items");
for (let i = 0; i < x.length; i++) {
if (elmnt != x[i] && elmnt != inp) {
x[i].parentNode.removeChild(x[i]);
}
}
}
/*点击 HTML 文档任意位置关闭填充列表*/
document.addEventListener("click", function (e) {
closeAllLists(e.target);
});
}
autocomplete(document.getElementById("myInput"), sites);
</script>
</body>
</html>
java:
@Test
void getRepository(ApplicationContext context) {
Map<String, Object> beansWithAnnotation = context.getBeansWithAnnotation(Repository.class);
System.out.println(beansWithAnnotation);
write(packaging(beansWithAnnotation));
}
private List<KeyValueVo> packaging(Map<String, ?> map) {
return map
.entrySet()
.stream()
.map(e -> {
var k = e.getKey();
var v = e.getValue();
if (v instanceof JpaRepository<?, ?> jpa) {
try {
return jpa
.findAll()
.stream()
.findFirst()
.map(o -> KeyValueVo.builder().key(k).value(String.valueOf(getId(o))).build())
.orElse(null);
} catch (Exception exp) {
exp.printStackTrace();
throw new RuntimeException(exp);
}
}
return null;
})
.collect(Collectors.toList());
}
private Object getId(Object o) {
if (o instanceof BasicEntity basicEntity) {
return basicEntity.getId();
}
return null;
}
private void write(List<?> result) {
String content = JSONUtil.toJsonStr(result);
try {
Path file = Paths.get("D:\\id.json");
Files.writeString(file, content);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
使用java主要是用于生成相应的id数据
输入所关联的repository,选中之后可渲染id。
赋值这串id就可以减少频繁的查询数据库啦!!
★,°:.☆( ̄▽ ̄)/$:.°★ 。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)