integrated_traffic/src/main/java/com/zcloud/entity/PageData.java

143 lines
3.2 KiB
Java
Raw Normal View History

2024-01-03 09:48:43 +08:00
package com.zcloud.entity;
2024-01-03 11:04:18 +08:00
import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
import javax.servlet.http.HttpServletRequest;
2024-01-03 09:48:43 +08:00
import java.io.BufferedReader;
import java.io.Reader;
2024-01-03 11:04:18 +08:00
import java.util.*;
2024-01-03 09:48:43 +08:00
2024-01-03 11:04:18 +08:00
/**
* Map
2024-01-03 09:48:43 +08:00
*/
public class PageData extends HashMap<Object, Object> implements Map<Object, Object> {
private static final long serialVersionUID = 1L;
Map<Object, Object> map = null;
HttpServletRequest request;
public PageData(HttpServletRequest request) {
this.request = request;
Map properties = request.getParameterMap();
Map<Object, Object> returnMap = new HashMap<Object, Object>();
Iterator<Object> entries = properties.entrySet().iterator();
2024-01-03 11:04:18 +08:00
Entry<Object, Object> entry;
2024-01-03 09:48:43 +08:00
String name = "";
String value = "";
while (entries.hasNext()) {
2024-01-03 11:04:18 +08:00
entry = (Entry<Object, Object>) entries.next();
2024-01-03 09:48:43 +08:00
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();
}
returnMap.put(name, value);
}
map = returnMap;
}
public PageData() {
map = new HashMap<Object, Object>();
}
@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) {
2024-01-11 09:15:22 +08:00
return get(key) == null ? null : get(key).toString().trim();
2024-01-03 09:48:43 +08:00
}
@Override
public Object put(Object key, Object value) {
if (value instanceof ClobProxyImpl) { // 读取oracle Clob类型数据
try {
ClobProxyImpl cpi = (ClobProxyImpl) value;
Reader is = cpi.getCharacterStream(); // 获取流
BufferedReader br = new BufferedReader(is);
String str = br.readLine();
StringBuffer sb = new StringBuffer();
while (str != null) { // 循环读取数据拼接到字符串
sb.append(str);
sb.append("\n");
str = br.readLine();
}
value = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
return map.put(key, value);
}
@Override
public Object remove(Object key) {
return map.remove(key);
}
public void clear() {
map.clear();
}
public boolean containsKey(Object key) {
// TODO Auto-generated method stub
return map.containsKey(key);
}
public boolean containsValue(Object value) {
// TODO Auto-generated method stub
return map.containsValue(value);
}
public Set entrySet() {
// TODO Auto-generated method stub
return map.entrySet();
}
public boolean isEmpty() {
// TODO Auto-generated method stub
return map.isEmpty();
}
public Set keySet() {
// TODO Auto-generated method stub
return map.keySet();
}
@SuppressWarnings("unchecked")
public void putAll(Map t) {
// TODO Auto-generated method stub
map.putAll(t);
}
public int size() {
// TODO Auto-generated method stub
return map.size();
}
public Collection values() {
// TODO Auto-generated method stub
return map.values();
}
}