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