当前位置:网站首页>手写数据库客户端
手写数据库客户端
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>
边栏推荐
- 【若依(ruoyi)】启用迷你导航栏
- Large scale DDoS attacks take Myanmar offline
- 【Kubernetes 系列】一文學會Kubernetes Service安全的暴露應用
- Gifcam v7.0 minimalist GIF animation recording tool Chinese single file version
- 球面透镜与柱面透镜
- 米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析
- Shell script updates stored procedure to database
- C语言sizeof和strlen的区别
- "Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
- Summary of Bible story reading
猜你喜欢
codeforces每日5题(均1700)-第六天
2345文件粉碎,文件强力删除工具无捆绑纯净提取版
一个复制也能玩出花来
【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
[Yu Yue education] basic reference materials of digital electronic technology of Xi'an University of Technology
Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?
微服务注册与发现
不赚钱的科大讯飞,投资价值该怎么看?
有没有完全自主的国产化数据库技术
随机推荐
2.11 simulation summary
Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
Is there a completely independent localization database technology
CSP numeric sort
Déduisez la question d'aujourd'hui - 729. Mon emploi du temps I
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.3 linear algebra_ Learning thinking and exercise answers
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
【若依(ruoyi)】ztree 自定义图标(iconSkin 属性)
Self made CA certificate and SSL certificate using OpenSSL
Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
[Chongqing Guangdong education] higher mathematics I reference materials of Southwest Petroleum University
[pointer training - eight questions]
Master data management theory and Practice
Trends in DDoS Attacks
2345文件粉碎,文件强力删除工具无捆绑纯净提取版
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
Redis SDS principle
PMP每日一练 | 考试不迷路-7.5