当前位置:网站首页>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>
边栏推荐
- Codeworks 5 questions per day (1700 average) - day 6
- MySQL advanced notes
- 原型图设计
- Rust language -- iterators and closures
- resulttype和resultmap的区别和应用场景
- Audio-AudioRecord Binder通信机制
- Atcoder beginer contest 233 (a~d) solution
- [Chongqing Guangdong education] higher mathematics I reference materials of Southwest Petroleum University
- Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
- 深度解析链动2+1模式,颠覆传统卖货思维?
猜你喜欢
![[ruoyi] set theme style](/img/e9/6a6b7113faed16c3b439230806320b.png)
[ruoyi] set theme style

如何精准识别主数据?

Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
![[matlab] access of variables and files](/img/cf/6f3cfdc4310fcf0bdcaa776d68261e.jpg)
[matlab] access of variables and files

电机控制反Park变换和反Clarke变换公式推导

GifCam v7.0 极简GIF动画录制工具中文单文件版

微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器

Web security SQL injection vulnerability (1)

Introduction to robotframework (I) brief introduction and use

Modeling specifications: naming conventions
随机推荐
2.11 simulation summary
The difference between sizeof and strlen in C language
What is the investment value of iFLYTEK, which does not make money?
Function knowledge points
手写数据库客户端
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
My C language learning record (blue bridge) -- under the pointer
Communication between microservices
解决:AttributeError: ‘str‘ object has no attribute ‘decode‘
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
Reverse repackaging of wechat applet
XSS challenges绕过防护策略进行 XSS 注入
Introduction to robotframework (II) app startup of appui automation
Fault analysis | analysis of an example of MySQL running out of host memory
resulttype和resultmap的区别和应用场景
Self made CA certificate and SSL certificate using OpenSSL
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
【若依(ruoyi)】启用迷你导航栏
[unity3d] GUI control
A copy can also produce flowers