hutool的SQL格式化,不能处理带注释的内容。

修改为使用JSQLFormatter开源项目来处理。
This commit is contained in:
tmlx1990
2023-12-06 18:13:48 +08:00
parent 2b15025f4b
commit add658c7b5
2 changed files with 9 additions and 3 deletions

View File

@ -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>

View File

@ -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);
}
}