Commit f2145209 authored by 黎博's avatar 黎博

sql执行接口新增insert支持

parent 432a90ad
......@@ -2,6 +2,7 @@ package cn.qg.qaplatform.controller.common;
import cn.qg.qaplatform.config.SwitchDataSource;
import cn.qg.qaplatform.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
......@@ -9,6 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/sql")
......@@ -27,6 +29,7 @@ public class SqlController {
*/
@GetMapping("/execute")
public JsonResult executeSQL(String namespace, String database, String sql, String type) {
log.info("收到sql请求,环境:{}, 数据库: {}, sql: {}, type: {}", namespace, database, sql, type);
try {
SwitchDataSource.dataSourceSwitch(namespace, database);
if (sql.startsWith("select") || sql.startsWith("SELECT")) {
......@@ -38,7 +41,8 @@ public class SqlController {
return JsonResult.serverFailed("暂不支持该类型!");
}
} else if (sql.startsWith("update") || sql.startsWith("UPDATE")
|| sql.startsWith("delete") || sql.startsWith("DELETE")) {
|| sql.startsWith("delete") || sql.startsWith("DELETE")
|| sql.startsWith("insert") || sql.startsWith("INSERT")) {
jdbcTemplate.execute(sql);
return JsonResult.success();
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment