From 1cad14bca191807e18705c3a5526eda8151be439 Mon Sep 17 00:00:00 2001 From: zhanghua <314079846@qq.com> Date: 星期一, 14 四月 2025 23:10:22 +0800 Subject: [PATCH] 批量审核和图片保存bug --- ycl-platform/src/main/java/com/ycl/common/util/ParamsMap.java | 248 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 248 insertions(+), 0 deletions(-) diff --git a/ycl-platform/src/main/java/com/ycl/common/util/ParamsMap.java b/ycl-platform/src/main/java/com/ycl/common/util/ParamsMap.java new file mode 100644 index 0000000..6df2b8a --- /dev/null +++ b/ycl-platform/src/main/java/com/ycl/common/util/ParamsMap.java @@ -0,0 +1,248 @@ +package com.ycl.common.util; + +import lombok.extern.slf4j.Slf4j; + +import javax.servlet.http.HttpServletRequest; +import java.io.Serializable; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; + +@Slf4j +public class ParamsMap extends HashMap<String, Object> implements Serializable{ + + private static final long serialVersionUID = -6716714932665322981L; + + public ParamsMap(){} + + public ParamsMap(HttpServletRequest request) { + if(request==null)return; + Iterator<Entry<String, String[]>> entries = request.getParameterMap().entrySet().iterator(); + Entry<String, String[]> entry; + String name = ""; + while (entries.hasNext()) { + String value = ""; + entry = (Entry<String, String[]>) entries.next(); + name = (String) entry.getKey(); + Object valueObj = entry.getValue(); + if(null == valueObj){ + value = ""; + }else if(valueObj instanceof String[]){ + String[] values = (String[])valueObj; + for(int i=0;i<values.length;i++){ + value += values[i] + ","; + } + value = value.substring(0, value.length()-1); + }else{ + value = valueObj.toString(); + } + this.put(name, value); + } + } + + public ParamsMap(String code, Object value) { + this.put(code, value); + } + + /** + * + * @Title: getString + * @Description: 鑾峰彇瀛楃涓插�� + * @param key + * @return + */ + public String getString(String key) { + try { + if (containsKey(key)) { + if(get(key)!=null) return get(key).toString(); + } + } catch (Exception e) { + log.error("ParamsMap getString is error:{}",e); + } + return null; + } + + /** + * + * @Title: getInteter + * @Description: 鑾峰彇鏁村瀷鍊� + * @param key + * @return + */ + public Integer getInteter(String key) { + try { + if (containsKey(key)) { + if(get(key)!=null && !"".equals(get(key))) + return Integer.parseInt(getString(key)); + } + } catch (Exception e) { + log.error("ParamsMap getInteter is error:{}",e); + } + return null; + } + + /** + * + * @Title: getAsLong + * @Description: 鑾峰彇Long鍊� + * @param key + * @return + */ + public Long getLong(String key){ + try { + if (containsKey(key)) { + if(get(key)!=null && !"".equals(get(key))) + return Long.parseLong(getString(key)); + } + } catch (Exception e) { + log.error("ParamsMap getLong is error:{}",e); + } + return null; + } + + /** + * + * @Title: getAsDouble + * @Description: 鑾峰彇Double鍊� + * @param key + * @return + */ + public Double getDouble(String key){ + try { + if (containsKey(key)) { + if(get(key)!=null && !"".equals(get(key))) + return Double.parseDouble(getString(key)); + } + } catch (Exception e) { + log.error("ParamsMap getDouble is error:{}",e); + } + return null; + } + + /** + * + * @Title: getFloat + * @Description: 鑾峰彇Float鍊� + * @param key + * @return + */ + public Float getFloat(String key){ + try { + if (containsKey(key)) { + if(get(key)!=null && !"".equals(get(key))) + return Float.parseFloat(getString(key)); + } + } catch (Exception e) { + log.error("ParamsMap getFloat is error:{}",e); + } + return null; + } + + /** + * + * @Title: getBoolean + * @Description: 鑾峰彇Boolean鍊� + * @param key + * @return + */ + public Boolean getBoolean(String key){ + try { + if (containsKey(key)) { + if(get(key)!=null && !"".equals(get(key))) + return Boolean.parseBoolean(getString(key)); + } + } catch (Exception e) { + log.error("ParamsMap getBoolean is error:{}",e); + } + return null; + } + + /** + * + * @Title: getDate + * @Description: 鑾峰彇鏃ユ湡鍊� + * @param key + * @return + */ + public Date getDate(String key){ + try { + if (containsKey(key)) { + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + if(get(key)!=null && !"".equals(get(key))) + return df.parse(get(key).toString()); + } + } catch (Exception e) { + log.error("ParamsMap getDate is error:{}",e); + } + return null; + } + + /** + * + * @Title: getStringArray + * @Description: 鑾峰彇瀛楃涓叉暟缁� + * @param key + * @return + */ + public String[] getArray(String key){ + try { + if (containsKey(key)) { + if(get(key)==null && !"".equals(get(key))) return new String[0]; + return get(key).toString().split(","); + } + } catch (Exception e) { + log.error("ParamsMap getStringArray is error:{}",e); + e.printStackTrace(); + } + return null; + } + + + /** + * + * @Title: getIntegerArray + * @Description: 鑾峰彇鏁村瀷鏁扮粍 + * @param key + * @return + */ + public Integer[] getIntegerArray(String key){ + try { + if (containsKey(key)) { + String [] tmp = getArray(key); + if(tmp==null)return null; + Integer []tmpInt = new Integer[tmp.length]; + int index = 0; + for(String s:tmp){ + if(s==null||s.equals(""))continue; + tmpInt[index]=Integer.parseInt(s); + } + return tmpInt; + } + } catch (Exception e) { + log.error("ParamsMap getAsIntegerArray is error:{}",e); + e.printStackTrace(); + } + return null; + } + + public Long[] getLongArray(String key) { + try { + if(containsKey(key)) { + String [] tmp = getArray(key); + if(tmp==null)return null; + Long [] tmpInt = new Long[tmp.length]; + int index = 0; + for(String s:tmp){ + if(s==null||s.equals(""))continue; + tmpInt[index]=Long.parseLong(s); + } + return tmpInt; + } + } catch (Exception e) { + log.error("ParamsMap getLongArray is error:{}",e); + e.printStackTrace(); + } + return null; + } +} \ No newline at end of file -- Gitblit v1.8.0