当前位置:网站首页>手写数据库客户端
手写数据库客户端
2022-07-06 02:58:00 【今夜月色很美】
controller
@Autowired
private IExecSqlService execSqlService;
@Log(title = "执行sql", businessType = BusinessType.OTHER)
@PostMapping("/exec")
public Response<?> exec(@RequestBody ExecSqlVo execSqlVo){
if (StringUtils.isBlank(execSqlVo.getSqlCommand())){
throw new CustomException("待执行sql不能为空");
}
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="请输入待执行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;">执行sql</el-button>
</el-form>
<el-row>
<el-col :span="4">执行结果:</el-col>
</el-row><br/>
<el-table border style="width: 100%" :data="resultTable" id="table">
<!-- 动态列表渲染 -->
<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: {
// 是否有已修改
reload: { type: Boolean, default: false },
orgTypeOptions: { type: Array, default: () => [] }
},
data() {
return {
resultTable: [], //查看数据处理后的数据
result: [], //查看数据用于循环的数据
// 查询参数
queryParams: {
sqlCommand: null
},
// 菜单ID
menuId: this.$route.meta.menuId,
}
},
methods: {
/**点击当前行 */
rowClick(row) {
this.selectRow = row
},
/** 查询列表 */
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()
})
},
/** 搜索按钮操作 */
handleQuery() {
if(!this.queryParams.sqlCommand){
this.$message({
type: 'warn',
message: `待执行sql为空`
});
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>
边栏推荐
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
- What are the principles of software design (OCP)
- OCR文字识别方法综述
- [unity3d] GUI control
- Li Kou today's question -729 My schedule I
- codeforces每日5题(均1700)-第六天
- Shell script updates stored procedure to database
- 【若依(ruoyi)】启用迷你导航栏
- Force buckle 146 LRU cache
- Pure QT version of Chinese chess: realize two-man, man-machine and network games
猜你喜欢
CobaltStrike-4.4-K8修改版安装使用教程
My C language learning records (blue bridge) -- files and file input and output
My C language learning record (blue bridge) -- under the pointer
力扣今日題-729. 我的日程安排錶 I
[matlab] access of variables and files
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
codeforces每日5题(均1700)-第六天
【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service
Gifcam v7.0 minimalist GIF animation recording tool Chinese single file version
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
随机推荐
Add one to non negative integers in the array
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
Codeforces 5 questions par jour (1700 chacune) - jour 6
My C language learning record (blue bridge) -- under the pointer
Web security SQL injection vulnerability (1)
有没有完全自主的国产化数据库技术
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
MySQL learning notes-10-tablespace recycling
球面透镜与柱面透镜
A copy can also produce flowers
Redis SDS principle
Introduction to robotframework (II) app startup of appui automation
Installation and use tutorial of cobaltstrike-4.4-k8 modified version
DDoS attacks - are we really at war?
Network Security Learning - Web vulnerabilities (Part 1)
Classic interview question [gem pirate]
Trends in DDoS Attacks
C # create self host webservice
Function knowledge points
PMP practice once a day | don't get lost in the exam -7.5