public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int start = Integer.valueOf(request.getParameter("start"));
int limit = Integer.valueOf(request.getParameter("limit"));
String jsonStr = null;
Map<String, Object> jsonObj = new HashMap<String, Object>();
List<Person> persons = new ArrayList<Person>();
int totalCount = 20;
for (int i = 1; i <= totalCount; i++) {
Person p = new Person(i, "路人" + i, new Date());
persons.add(p);
}
persons = persons.subList(start, limit+start);
jsonObj.put("data", persons);
jsonObj.put("totalCount", totalCount);
response.setContentType("application/x-json");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
Gson gson = new Gson();
jsonStr = gson.toJson(jsonObj);
out.print(jsonStr);
out.close();
}
转载于:https://blog.51cto.com/2388249/1279790