java接收參數和返回資料實體類封裝1

來源:互聯網
上載者:User

標籤:while   map   else   length   imp   stat   nmap   i++   str   

public class PageData extends HashMap implements Map {    private static final long serialVersionUID = 1L;    Map map = null;    HttpServletRequest request;    public PageData(HttpServletRequest request) {        this.request = request;        Map properties = request.getParameterMap();        Map returnMap = new HashMap();        Iterator entries = properties.entrySet().iterator();        Map.Entry entry;        String name = "";        String value = "";            while (entries.hasNext()) {            entry = (Map.Entry) 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();            }            if (name.equals("timeEnd")) {                if (!value.equals("")) {                    value = value + " 23:59:59";                } else {                }            }            returnMap.put(name, value);        }        map = returnMap;    }    public PageData(JSONObject jo) {        Map returnMap = new HashMap();        for (Iterator<String> keys = jo.keys(); keys.hasNext();) {            try {                String key1 = keys.next();//                System.out.println("key1---" + key1 + "------" + jo.get(key1) + (jo.get(key1) instanceof JSONObject)//                        + jo.get(key1) + (jo.get(key1) instanceof JSONArray));//                System.out.println("key1:" + key1 + "----------jo.get(key1):" + jo.get(key1));                returnMap.put(key1.toUpperCase(), jo.get(key1));            } catch (JSONException e) {                e.printStackTrace();            }        }        map = returnMap;    }    public PageData() {        map = new HashMap();    }    @Override    public Object get(Object key) {        Object obj = null;        if (map.get(key) instanceof Object[]) {            Object[] arr = (Object[]) map.get(key);            obj = request == null ? arr : (request.getParameter((String) key) == null ? arr : arr[0]);        } else {            obj = map.get(key);        }        return obj;    }    public String getString(Object key) {            if (null != get(key) && "null" != get(key)) {            return String.valueOf(get(key));        }        return "";    }    public double getDouble(Object key) {        Object value = get(key);        if (null != value && !"null".equals(value) && !"".equals(value)) {            if (value instanceof String) {                return Double.parseDouble(value.toString());            } else if (value instanceof Double) {                return (double) value;            }            // return (double) get(key);        }        return 0.0;    }    public int getInt(Object key) {        Object value = get(key);        if (null != value && !"null".equals(value) && !"".equals(value)) {            if (value instanceof String) {                return Integer.parseInt(value.toString());            } else if (value instanceof Integer) {                return (int) value;            }        }        return 0;    }

其本質就是一個HashMap

java接收參數和返回資料實體類封裝1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.