From fc61e10b1ada300c8566d19d8fc0df9560f4ccc7 Mon Sep 17 00:00:00 2001 From: miaopeng Date: Fri, 18 Nov 2022 14:28:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF:=E6=89=93?= =?UTF-8?q?=E5=8C=85=E4=B9=8B=E5=90=8E=EF=BC=8Cspring=E6=B2=A1=E5=8A=9E?= =?UTF-8?q?=E6=B3=95=E9=80=9A=E8=BF=87File=E7=9A=84=E5=BD=A2=E5=BC=8F?= =?UTF-8?q?=E8=AE=BF=E9=97=AEjar=E5=8C=85=E9=87=8C=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gitee/freakchicken/DBApi.java | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gitee/freakchicken/DBApi.java b/src/main/java/com/gitee/freakchicken/DBApi.java index 7135b73..7d50ed4 100644 --- a/src/main/java/com/gitee/freakchicken/DBApi.java +++ b/src/main/java/com/gitee/freakchicken/DBApi.java @@ -1,19 +1,22 @@ package com.gitee.freakchicken; -import com.github.freakchick.orange.SqlMeta; -import com.github.freakchick.orange.engine.DynamicSqlEngine; import com.gitee.freakchicken.entity.DBConfig; import com.gitee.freakchicken.entity.DataSource; import com.gitee.freakchicken.entity.ResponseDto; import com.gitee.freakchicken.entity.Sql; import com.gitee.freakchicken.util.JdbcUtil; import com.gitee.freakchicken.util.XmlParser; - +import com.github.freakchick.orange.SqlMeta; +import com.github.freakchick.orange.engine.DynamicSqlEngine; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.springframework.core.io.ClassPathResource; import org.springframework.util.ResourceUtils; import java.io.File; +import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Map; @@ -37,13 +40,27 @@ public class DBApi { this.dbConfig = dbConfig; try { - File file = ResourceUtils.getFile(this.dbConfig.getSql()); - String content = FileUtils.readFileToString(file, StandardCharsets.UTF_8); - this.sqlMap = XmlParser.parseSql(content); + String sqlContent; + try { + File sqlFile = ResourceUtils.getFile(this.dbConfig.getSql()); + sqlContent = FileUtils.readFileToString(sqlFile, StandardCharsets.UTF_8); + } catch (Exception exception) { + ClassPathResource sqlResource = new ClassPathResource(this.dbConfig.getSql()); + InputStream sqlInputStream = sqlResource.getInputStream(); + sqlContent = IOUtils.toString(sqlInputStream, Charsets.toCharset(StandardCharsets.UTF_8)); + } + this.sqlMap = XmlParser.parseSql(sqlContent); - File dsFile = ResourceUtils.getFile(this.dbConfig.getDatasource()); - String dsText = FileUtils.readFileToString(dsFile, StandardCharsets.UTF_8); - this.dataSourceMap = XmlParser.parseDatasource(dsText); + String dsContent; + try { + File dsFile = ResourceUtils.getFile(this.dbConfig.getDatasource()); + dsContent = FileUtils.readFileToString(dsFile, StandardCharsets.UTF_8); + } catch (Exception exception) { + ClassPathResource dsResource = new ClassPathResource(this.dbConfig.getDatasource()); + InputStream dsInputStream = dsResource.getInputStream(); + dsContent = IOUtils.toString(dsInputStream, Charsets.toCharset(StandardCharsets.UTF_8)); + } + this.dataSourceMap = XmlParser.parseDatasource(dsContent); } catch (Exception e) { e.printStackTrace(); } -- Gitee