package com.gaowj.formtable.action; import java.sql.SQLException; import java.text.ParseException; import java.util.HashMap; import java.util.List; import java.util.Map; import net.sf.json.JSONObject; import com.gaowj.business.FormtableBusiness; import com.gaowj.business.StudentBusiness; import com.gaowj.business.action.BasicAction; import com.gaowj.business.comp.BusinessManager; import com.gaowj.business.exception.BusinessException; import com.gaowj.business.util.Page; import com.gaowj.business.util.PropUtil; import com.gaowj.business.util.QueryParamUtil; import com.gaowj.business.util.RequestUtils; import com.gaowj.business.util.SessionUtil; import com.gaowj.business.util.TestMd5; import com.gaowj.standard.utils.CacheKit; public class dataAction extends BasicAction{ /** * */ private static final long serialVersionUID = -5059421324729466816L; private JSONObject jsonObject = new JSONObject(); private int rows = 20;// 每页显示的记录数 private int page = 1;// 当前第几页 public JSONObject getJsonObject() { return jsonObject; } public void setJsonObject(JSONObject jsonObject) { this.jsonObject = jsonObject; } public int getRows() { return rows; } public void setRows(int rows) { this.rows = rows; } public int getPage() { return page; } public void setPage(int page) { this.page = page; } /** * 分页获取记录 * @param entity * @throws BusinessException */ public String list() throws BusinessException { FormtableBusiness business = BusinessManager.getBusiness(FormtableBusiness.class); Map<String, Object> query = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX); try { query = QueryParamUtil.StringToDate(query); Page<Map<String, Object>> pageRows = business.list_form_table(pageNo,pageSize, query); setPageCount((pageRows.getCount() - 1) / pageSize + 1); Map<String, Object> data = new HashMap<String, Object>(); data.put("rowSet", QueryParamUtil.DateToString(pageRows.getItems())); data.put("pageNo", pageNo); data.put("pageSize", pageSize); data.put("pageCount", pageCount); data.put("rows", data.get("rowSet")); data.put("total", pageRows.getCount()); jsonObject = new JSONObject(); jsonObject.putAll(data); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "json"; } public String listFormTable() throws BusinessException{ FormtableBusiness business = BusinessManager.getBusiness(FormtableBusiness.class); Map<String, Object> query = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX); try { query = QueryParamUtil.StringToDate(query); List<Map<String,Object>> listRows = business.list_form_table(query); Map<String, Object> data = new HashMap<String, Object>(); data.put("rowSet", QueryParamUtil.DateToString(listRows)); data.put("pageNo", pageNo); data.put("pageSize", pageSize); data.put("pageCount", pageCount); data.put("rows", data.get("rowSet")); data.put("total", listRows.size()); jsonObject = new JSONObject(); jsonObject.putAll(data); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "json"; } }