From 4393d934ba300601a91084763616ea80379b550e Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 28 十一月 2023 18:44:49 +0800 Subject: [PATCH] 修改 获取Excel模板 方法 --- src/main/java/com/moon/server/helper/FileHelper.java | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 44 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/moon/server/helper/FileHelper.java b/src/main/java/com/moon/server/helper/FileHelper.java index 8157d98..d33cf02 100644 --- a/src/main/java/com/moon/server/helper/FileHelper.java +++ b/src/main/java/com/moon/server/helper/FileHelper.java @@ -6,8 +6,11 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.context.support.ClassPathXmlApplicationContext; import java.io.*; +import java.net.URL; +import java.net.URLDecoder; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.StandardCharsets; @@ -367,7 +370,7 @@ // 鎵�浠ヨ〃绀烘垚 16 杩涘埗闇�瑕� 32 涓瓧绗︼紝琛ㄧず杞崲缁撴灉涓搴旂殑瀛楃浣嶇疆 int k = 0; // 浠庣涓�涓瓧鑺傚紑濮嬶紝瀵� MD5 鐨勬瘡涓�涓瓧鑺� - for (int i = 0; i < StaticData.SIXTEEN; i++) { + for (int i = 0; i < StaticData.I16; i++) { // 杞崲鎴� 16 杩涘埗瀛楃鐨勮浆鎹� byte byte0 = tmp[i]; // 鍙栧瓧鑺備腑楂� 4 浣嶇殑鏁板瓧杞崲 @@ -445,4 +448,44 @@ is.close(); } } + + /** + * 杩囨护杈撳叆瀛楃涓�, 鍓旈櫎澶氳娉ㄩ噴浠ュ強鏇挎崲鎺夊弽鏂滄潬 + */ + public static String filter(String str) { + return str.replaceAll("/\\*[\\s\\S]*?\\*/", ""); + } + + /** + * 瑙g爜 + */ + public static String decode(String str) { + try { + return URLDecoder.decode(str, "UTF-8"); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + return null; + } + } + + /** + * 鑾峰彇ClassPath-jar + */ + public static String getClassPathForJar() { + URL resource = ClassLoader.getSystemResource(""); + if (null == resource) { + return null; + } + + return decode(filter(resource.getPath())); + } + + /** + * 鑾峰彇ClassPath-war + */ + public static String getClassPathForWar() throws IOException { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); + + return context.getResource("").getFile().getAbsolutePath(); + } } -- Gitblit v1.9.3