|
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
package com.unis.crk.utils;
|
|
2
|
2
|
|
|
3
|
|
-import org.springframework.core.io.UrlResource;
|
|
|
3
|
+import cn.hutool.core.io.resource.ClassPathResource;
|
|
|
4
|
+import org.apache.commons.io.IOUtils;
|
|
4
|
5
|
import org.springframework.util.ResourceUtils;
|
|
5
|
6
|
|
|
6
|
7
|
import java.io.FileInputStream;
|
|
|
@@ -12,9 +13,10 @@ public class SqpMapUtil {
|
|
12
|
13
|
private final static Map<String, String> SQL_MAP =new LinkedHashMap<>();
|
|
13
|
14
|
static {
|
|
14
|
15
|
try {
|
|
15
|
|
- URL url1 = ResourceUtils.getURL("classpath:SqlMap/sql.xml");
|
|
16
|
|
- UrlResource resource1 = new UrlResource(url1);
|
|
17
|
|
- Xml xml = new Xml(new FileInputStream(resource1.getFile()));
|
|
|
16
|
+ //此种写法在打包jar情况下能正常使用
|
|
|
17
|
+ URL url1 = ResourceUtils.getURL("classpath:SqlMap/sql.xml");
|
|
|
18
|
+ String mapping = IOUtils.toString(url1);
|
|
|
19
|
+ Xml xml = new Xml(mapping);
|
|
18
|
20
|
Map<String, String> sqls_ = xml.getText();
|
|
19
|
21
|
for (Map.Entry<String, String> entry : sqls_.entrySet()) {
|
|
20
|
22
|
SQL_MAP.put(entry.getKey(), entry.getValue());
|
|
|
@@ -25,6 +27,21 @@ public class SqpMapUtil {
|
|
25
|
27
|
}
|
|
26
|
28
|
|
|
27
|
29
|
}
|
|
|
30
|
+// static {
|
|
|
31
|
+// try {
|
|
|
32
|
+// URL url1 = ResourceUtils.getURL("classpath:SqlMap/sql.xml");
|
|
|
33
|
+// UrlResource resource1 = new UrlResource(url1);
|
|
|
34
|
+// Xml xml = new Xml(new FileInputStream(resource1.getFile()));
|
|
|
35
|
+// Map<String, String> sqls_ = xml.getText();
|
|
|
36
|
+// for (Map.Entry<String, String> entry : sqls_.entrySet()) {
|
|
|
37
|
+// SQL_MAP.put(entry.getKey(), entry.getValue());
|
|
|
38
|
+// }
|
|
|
39
|
+//
|
|
|
40
|
+// } catch (Exception e) {
|
|
|
41
|
+// e.printStackTrace();
|
|
|
42
|
+// }
|
|
|
43
|
+//
|
|
|
44
|
+// }
|
|
28
|
45
|
public static String getSql(String key) {
|
|
29
|
46
|
return SQL_MAP.get(key);
|
|
30
|
47
|
|