data.jsp
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<%@page import="net.sf.json.JSONArray"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="weaver.general.Util"%>
<%@ page import="java.io.UnsupportedEncodingException" %>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="com.weaver.formmodel.util.StringHelper" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/mobilemode/mobile/base.jsp"%>
<%
int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
String searchKey = Util.null2String(request.getParameter("searchKey"));
try {
searchKey = URLDecoder.decode(searchKey, "utf-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
List<JSONObject> datas = new ArrayList<JSONObject>();
datas.add(JSONObject.fromObject("{'id':'1','name':'上海A公司', 'catogary':'办公家具','first':'1,233.000', 'second':'7285.50', 'third':'6543.00','fourth':'9088.00'}"));
datas.add(JSONObject.fromObject("{'id':'2','name':'上海A公司', 'catogary':'个人借款','first':'2,131.50', 'second':'6540.00', 'third':'4980.00','fourth':'8088.00'}"));
datas.add(JSONObject.fromObject("{'id':'3','name':'上海B公司', 'catogary':'销售费用','first':'2,980.00', 'second':'9842.00', 'third':'8888.00','fourth':'7034.00'}"));
datas.add(JSONObject.fromObject("{'id':'4','name':'上海B公司', 'catogary':'管理费用','first':'1,260.50', 'second':'6656.00', 'third':'6666.00','fourth':'5088.00'}"));
datas.add(JSONObject.fromObject("{'id':'5','name':'上海B公司', 'catogary':'差旅费用','first':'2,450.34', 'second':'5550.00', 'third':'8988.50','fourth':'7088.00'}"));
datas.add(JSONObject.fromObject("{'id':'6','name':'上海B公司', 'catogary':'招待费用','first':'6,540.00', 'second':'7890.50', 'third':'9890.00','fourth':'8066.00'}"));
datas.add(JSONObject.fromObject("{'id':'7','name':'上海C公司', 'catogary':'销售费用','first':'7,689.00', 'second':'1456.00', 'third':'7650.00','fourth':'3039.00'}"));
datas.add(JSONObject.fromObject("{'id':'8','name':'上海C公司', 'catogary':'办公家具','first':'1,250.50', 'second':'9989.00', 'third':'6650.00','fourth':'2090.00'}"));
datas.add(JSONObject.fromObject("{'id':'9','name':'上海C公司', 'catogary':'管理费用','first':'2,500.00', 'second':'7689.00', 'third':'8745.00','fourth':'1088.88'}"));
datas.add(JSONObject.fromObject("{'id':'10','name':'上海C公司', 'catogary':'办公家具','first':'1,280.00', 'second':'9999.00', 'third':'6599.00','fourth':'4076.88'}"));
int startIndex = (pageNo - 1) * pageSize;
int endIndex = startIndex + pageSize;
List<JSONObject> result = new ArrayList<JSONObject>();
for(JSONObject obj : datas){
String objStr = obj.toString();
if(StringHelper.isNotEmpty(searchKey)){
if(objStr.indexOf(searchKey) != -1){
result.add(obj);
}
}else{
result.add(obj);
}
}
JSONObject json = new JSONObject();
int size = result.size();
json.put("totalSize", result.size());
json.put("datas", JSONArray.fromObject(result.subList(startIndex, endIndex > size ? size : endIndex)));;
out.print(json);
%>