当前位置:网站首页>Handwriting database client
Handwriting database client
2022-07-06 03:03:00 【The moonlight is beautiful tonight】
controller
@Autowired
private IExecSqlService execSqlService;
@Log(title = " perform sql", businessType = BusinessType.OTHER)
@PostMapping("/exec")
public Response<?> exec(@RequestBody ExecSqlVo execSqlVo){
if (StringUtils.isBlank(execSqlVo.getSqlCommand())){
throw new CustomException(" To be carried out sql Can't be empty ");
}
return okResponse(execSqlService.exec(execSqlVo.getSqlCommand()));
}
service
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.xxx.mapper.ExecSqlMapper;
import com.xxx.service.IExecSqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ExecSqlServiceImpl implements IExecSqlService {
@Autowired
private ExecSqlMapper execSqlMapper;
@Override
public Object exec(String sql) {
if (sql.startsWith("select") || sql.startsWith("SELECT")){
return (JSONArray)JSON.toJSON(execSqlMapper.execQuery(sql));
} else {
List result = new ArrayList();
Map<String, Object> map = new HashMap<>();
map.put("update rows", execSqlMapper.execUpdate(sql));
result.add(map);
return result;
}
}
}
mapper
import org.apache.ibatis.annotations.Mapper;
import java.util.LinkedHashMap;
import java.util.List;
@Mapper
public interface ExecSqlMapper {
List<LinkedHashMap<String, Object>> execQuery(String sql);
int execUpdate(String sql);
}
mapper.xml
<mapper namespace="com.xxx.mapper.ExecSqlMapper">
<select id="execQuery" parameterType="java.lang.String" resultType="java.util.LinkedHashMap">
${sql}
</select>
<update id="execUpdate" parameterType="java.lang.String">
${sql}
</update>
</mapper>
vue
<template>
<div class="app-container">
<el-form class="searchBar" :model="queryParams" ref="queryForm" :inline="true">
<el-input
type="textarea"
v-model="queryParams.sqlCommand"
placeholder=" Please enter to be executed sql"
rows="13"
clearable
style="margin-top: 20px;margin-bottom: 20px;width:80%;"/>
<el-button type="danger" @click="handleQuery" style="margin-left: 40px;margin-bottom: 20px;"> perform sql</el-button>
</el-form>
<el-row>
<el-col :span="4"> Execution results :</el-col>
</el-row><br/>
<el-table border style="width: 100%" :data="resultTable" id="table">
<!-- Dynamic list rendering -->
<el-table-column
width="150"
:label="item.label"
:prop="item.prop"
v-for="(item, key) in result"
:key="key"
>
</el-table-column>
</el-table>
</div>
</template>
<script>
import { execSql} from '@/api/system/exec-sql'
export default {
name: 'ExeSqlMng',
props: {
// Whether it has been modified
reload: { type: Boolean, default: false },
orgTypeOptions: { type: Array, default: () => [] }
},
data() {
return {
resultTable: [], // View the data after data processing
result: [], // View the data for the loop
// Query parameters
queryParams: {
sqlCommand: null
},
// menu ID
menuId: this.$route.meta.menuId,
}
},
methods: {
/** Click the current line */
rowClick(row) {
this.selectRow = row
},
/** Query list */
getList() {
const loading = this.$loading(this.GLOBAL.Loading);
execSql(this.queryParams)
.then(response => {
loading.close();
this.result = this.getCol(response.data);
this.resultTable = this.getTable(response.data);
})
.catch((e) => {
loading.close()
})
},
/** Search button operation */
handleQuery() {
if(!this.queryParams.sqlCommand){
this.$message({
type: 'warn',
message: ` To be carried out sql It's empty `
});
return
}
this.getList()
},
getCol(src) {
let col = [];
for (let j in src[0]) {
col.push({
prop: j,
label: j,
});
}
return col;
},
getTable(src) {
let table = [];
for (let i = 0; i < src.length; i++) {
let temp = {};
for (let j in src[i]) {
temp[j] = src[i][j];
}
table.push(temp);
}
return table;
},
}
}
</script>
<style scoped>
.el-form--inline .el-form-item {
display: inline-block;
margin-right: 10px;
vertical-align: top;
width: 1000px;
}
</style>
边栏推荐
- What is the investment value of iFLYTEK, which does not make money?
- 会员积分营销系统操作的时候怎样提升消费者的积极性?
- Referenceerror: primordials is not defined error resolution
- [matlab] access of variables and files
- 八道超经典指针面试题(三千字详解)
- JS regular filtering and adding image prefixes in rich text
- codeforces每日5题(均1700)-第六天
- 继承day01
- 【Unity3D】GUI控件
- [pointer training - eight questions]
猜你喜欢

【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service

Software design principles
![[ruoyi] enable Mini navigation bar](/img/28/a8b38aecd90c8ddc98333f0e2d3eab.png)
[ruoyi] enable Mini navigation bar

Qt发布exe软件及修改exe应用程序图标

Apt installation ZABBIX

一个复制也能玩出花来
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22](/img/e0/21367eeaeca10c0a2f2aab3a4fa1fb.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22

故障分析 | MySQL 耗尽主机内存一例分析

QT release exe software and modify exe application icon

OCR文字识别方法综述
随机推荐
CobaltStrike-4.4-K8修改版安装使用教程
Reverse repackaging of wechat applet
Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
BUUCTF刷题笔记——[极客大挑战 2019]EasySQL 1
建模规范:命名规范
华为、H3C、思科命令对比,思维导图形式从基础、交换、路由三大方向介绍【转自微信公众号网络技术联盟站】
这些不太会
【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service
js 正则过滤和增加富文本中图片前缀
PMP practice once a day | don't get lost in the exam -7.5
07 singleton mode
2.11 simulation summary
【Unity3D】GUI控件
Function knowledge points
2345 file shredding, powerful file deletion tool, unbound pure extract version
Yyds dry inventory comparison of several database storage engines
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
Introduction to robotframework (II) app startup of appui automation
【指针训练——八道题】
CSP date calculation