mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-30 03:03:13 +08:00
hutool的SQL格式化,不能处理带注释的内容。
修改为使用JSQLFormatter开源项目来处理。
This commit is contained in:
@ -89,6 +89,11 @@
|
|||||||
<artifactId>java-jwt</artifactId>
|
<artifactId>java-jwt</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.manticore-projects.jsqlformatter</groupId>
|
||||||
|
<artifactId>jsqlformatter</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -3,7 +3,7 @@ package ai.chat2db.server.web.api.controller.sql;
|
|||||||
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
|
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
|
||||||
import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
|
import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
|
||||||
import ai.chat2db.server.web.api.controller.sql.request.SqlFormatRequest;
|
import ai.chat2db.server.web.api.controller.sql.request.SqlFormatRequest;
|
||||||
import cn.hutool.db.sql.SqlFormatter;
|
import com.manticore.jsqlformatter.JSQLFormatter;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -19,18 +19,19 @@ public class SqlController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL Format
|
* SQL Format
|
||||||
|
*
|
||||||
* @param sqlFormatRequest
|
* @param sqlFormatRequest
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/format")
|
@GetMapping("/format")
|
||||||
public DataResult<String> list(@Valid SqlFormatRequest sqlFormatRequest) {
|
public DataResult<String> list(@Valid SqlFormatRequest sqlFormatRequest) {
|
||||||
|
|
||||||
String sql = sqlFormatRequest.getSql();
|
String sql = sqlFormatRequest.getSql();
|
||||||
try {
|
try {
|
||||||
sql = SqlFormatter.format(sql);
|
sql = JSQLFormatter.format(sql);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
return DataResult.of(sql);
|
return DataResult.of(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user