前端傳入 SQL 語句 到后端執行
本文運用注意事項:
(1)使用階段:測試階段,上生產前需去掉。
(2)作用:通過 系統 執行SQL,繞開權限的控制。
1. Controller
1 @ApiOperation(value = "test") 2 @PostMapping("/executeSql") 3 public Result<List<LinkedHashMap>> executeSql(@RequestParam("sql") String sql) { 4 return popReconciliationDomain.executeSql(sql); 5 } 6
2. Demon
1 2 @Transactional 3 public Result<List<LinkedHashMap>> executeSql(String sql){ 4 List<LinkedHashMap> integers = reconciliationPayRuleMapper.executeSql(sql); 5 return new Result(ResultCodeEnum.OK, integers); 6 }
3.Mapper.java
List<LinkedHashMap> executeSql(String sql);
4.mapper.xml
1 <select id="executeSql" parameterType="java.lang.String" resultType="java.util.LinkedHashMap" > 2 ${value} 3 </select> 4
通過post 請求,參數 key:sql;value: 具體的 SQL 語句。