From 56c25bcb0dc03aae78aba23f32ebbf548b866332 Mon Sep 17 00:00:00 2001 From: xing <xingjs@qq.com> Date: 星期三, 22 二月 2023 14:11:09 +0800 Subject: [PATCH] 20230221@xingjs@提交官网一张图相关内容接口 --- src/main/java/com/lf/server/helper/WebHelper.java | 86 ++++++++++++++++++++++++++++++++++++++----- 1 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/lf/server/helper/WebHelper.java b/src/main/java/com/lf/server/helper/WebHelper.java index 5a43d7d..57a4a1b 100644 --- a/src/main/java/com/lf/server/helper/WebHelper.java +++ b/src/main/java/com/lf/server/helper/WebHelper.java @@ -5,6 +5,8 @@ import com.lf.server.entity.all.ResponseMsg; import com.lf.server.entity.all.SettingData; import com.lf.server.entity.all.StaticData; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -19,9 +21,7 @@ import java.io.PrintWriter; import java.net.URLEncoder; import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Random; -import java.util.UUID; +import java.util.*; /** * Web甯姪绫� @@ -31,6 +31,8 @@ private final static String UNKNOWN = "unknown"; private final static String COMMA = ","; + + private final static Log log = LogFactory.getLog(WebHelper.class); /** * 鑾峰彇GUID @@ -277,6 +279,17 @@ } /** + * 鍐欏搷搴斾俊鎭� + */ + public static void writeInfo(HttpStatus status, String info, HttpServletResponse res) { + try { + WebHelper.write2Page(res, WebHelper.getErrJson(status, info)); + } catch (Exception e) { + // + } + } + + /** * 鑾峰彇闅忔満鏁存暟 */ public static int getRandomInt(int min, int max) { @@ -286,16 +299,20 @@ /** * 涓嬭浇鏂囦欢 * - * @param file 鏂囦欢 - * @param res 鍝嶅簲 + * @param file 鏂囦欢 + * @param fileName 鏂囦欢鍚� + * @param res 鍝嶅簲 * @throws Exception 寮傚父 */ - public static void download(String file, HttpServletResponse res) throws Exception { - String fileName = URLEncoder.encode(FileHelper.getFileName(file), "UTF-8"); + public static void download(String file, String fileName, HttpServletResponse res) throws Exception { + if (StringHelper.isEmpty(fileName)) { + fileName = StringHelper.YMDHMS2_FORMAT.format(new Date()); + } + fileName = URLEncoder.encode(fileName, "UTF-8").replace("+", "%20"); // 璁剧疆鍝嶅簲澶翠腑鏂囦欢鐨勪笅杞芥柟寮忎负闄勪欢鏂瑰紡锛屼互鍙婅缃枃浠跺悕 - res.setHeader("Content-Disposition", "attachment; filename=" + fileName); - // 璁剧疆鍝嶅簲澶寸殑缂栫爜鏍煎紡涓篣TF-8 + res.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + fileName); + // 璁剧疆鍝嶅簲澶寸殑缂栫爜鏍煎紡涓� UTF-8 res.setCharacterEncoding("UTF-8"); // 閫氳繃response瀵硅薄璁剧疆鍝嶅簲鏁版嵁鏍煎紡(濡傦細"text/plain; charset=utf-8") @@ -317,7 +334,56 @@ } // 鍏抽棴璧勬簮 - outputStream.close(); fileInputStream.close(); + outputStream.close(); + } + + /** + * 鎵ц鍛戒护 + * + * @param cmd 鍛戒护 + */ + public static void exec(String cmd) { + try { + Runtime.getRuntime().exec(cmd); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } + + /** + * 鑾峰彇璇锋眰鐨勫弬鏁板�� + * + * @param req 璇锋眰 + * @param key 鍙傛暟鍚� + * @return 鍙傛暟鍊� + */ + public static String getReqParamVal(HttpServletRequest req, String key) { + Map<String, String[]> maps = req.getParameterMap(); + for (Map.Entry<String, String[]> entry : maps.entrySet()) { + if (entry.getKey().equalsIgnoreCase(key)) { + return null == entry.getValue() || 0 == entry.getValue().length ? null : entry.getValue()[0]; + } + } + + return null; + } + + /** + * 鑾峰彇璇锋眰鐨勫弬鏁板�� + * + * @param req 璇锋眰 + * @param key 鍙傛暟鍚� + * @return 鍙傛暟鍊� + */ + public static String[] getReqParamVals(HttpServletRequest req, String key) { + Map<String, String[]> maps = req.getParameterMap(); + for (Map.Entry<String, String[]> entry : maps.entrySet()) { + if (entry.getKey().equalsIgnoreCase(key)) { + return entry.getValue(); + } + } + + return null; } } -- Gitblit v1.9.3