当前位置:网站首页>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>
边栏推荐
- Classic interview question [gem pirate]
- Single instance mode of encapsulating PDO with PHP in spare time
- Fault analysis | analysis of an example of MySQL running out of host memory
- Résumé des méthodes de reconnaissance des caractères ocr
- A copy can also produce flowers
- How does yyds dry inventory deal with repeated messages in the consumption process?
- Software design principles
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
- [Yu Yue education] basic reference materials of digital electronic technology of Xi'an University of Technology
- Audio-AudioRecord Binder通信机制
猜你喜欢
What is the investment value of iFLYTEK, which does not make money?
【概念】Web 基础概念认知
电机控制反Park变换和反Clarke变换公式推导
CobaltStrike-4.4-K8修改版安装使用教程
PMP每日一练 | 考试不迷路-7.5
C # create self host webservice
2345 file shredding, powerful file deletion tool, unbound pure extract version
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
有没有完全自主的国产化数据库技术
OCR文字识别方法综述
随机推荐
#PAT#day10
jsscript
The difference between sizeof and strlen in C language
How to improve the enthusiasm of consumers when the member points marketing system is operated?
How to read excel, PDF and JSON files in R language?
Differences and application scenarios between resulttype and resultmap
Zhang Lijun: penetrating uncertainty depends on four "invariants"
Pat 1084 broken keyboard (20 points) string find
银行核心业务系统性能测试方法
Taobao focus map layout practice
Introduction to robotframework (II) app startup of appui automation
CSP date calculation
IPv6 jobs
故障分析 | MySQL 耗尽主机内存一例分析
Network Security Learning - Web vulnerabilities (Part 1)
C # create self host webservice
Linear programming matlab
QT release exe software and modify exe application icon
[matlab] access of variables and files
微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器