当前位置:网站首页>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>
边栏推荐
- 【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service
- 手写数据库客户端
- 张丽俊:穿透不确定性要靠四个“不变”
- [pointer training - eight questions]
- 【概念】Web 基础概念认知
- Codeforces 5 questions par jour (1700 chacune) - jour 6
- Detailed use of dbutils # yyds dry goods inventory #
- Pat 1046 shortest distance (20 points) simulation
- [Yu Yue education] basic reference materials of digital electronic technology of Xi'an University of Technology
- Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
猜你喜欢
My C language learning records (blue bridge) -- files and file input and output
XSS challenges bypass the protection strategy for XSS injection
Sign SSL certificate as Ca
建模规范:命名规范
淘宝焦点图布局实战
PMP practice once a day | don't get lost in the exam -7.5
Codeforces 5 questions par jour (1700 chacune) - jour 6
华为、H3C、思科命令对比,思维导图形式从基础、交换、路由三大方向介绍【转自微信公众号网络技术联盟站】
CobaltStrike-4.4-K8修改版安装使用教程
全国大学生信息安全赛创新实践赛初赛---misc(永恒的夜)
随机推荐
有没有完全自主的国产化数据库技术
Communication between microservices
How to improve the enthusiasm of consumers when the member points marketing system is operated?
Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
Solution: attributeerror: 'STR' object has no attribute 'decode‘
如何精准识别主数据?
MySQL learning notes-10-tablespace recycling
Trends in DDoS Attacks
RobotFramework入门(二)appUI自动化之app启动
PMP每日一练 | 考试不迷路-7.5
[Chongqing Guangdong education] higher mathematics I reference materials of Southwest Petroleum University
Custom attribute access__ getattribute__/ Settings__ setattr__/ Delete__ delattr__ method
Maturity of master data management (MDM)
Qt发布exe软件及修改exe应用程序图标
MySQL advanced notes
Taobao focus map layout practice
4. File modification
I sorted out a classic interview question for my job hopping friends
Network Security Learning - Web vulnerabilities (Part 1)
Linear programming matlab