java后台的数据层数据组织
2016-01-15 23:19
441 查看
1、DataGrid的数据组织—service在事物内
(1)action
(2)service
(3)数据:
2、HashMap
(1)action:
(1)action
public void getExchange() { this.writeJson(orderService.getExchange(exchange)); }
(2)service
StringBuffer data = new StringBuffer(); Map<String, Object> params = new HashMap<String, Object>(); data.append(" from Texchange as t where t.isValid=1"); if (ex.getUserId() != null) { data.append(" and t.userId=:userId"); params.put("userId", ex.getUserId()); } String count = "select count(*)" + data.toString(); if (ex.getSort() != null) { data.append(" order by" + ex.getSort() + " " + ex.getOrder()); } try { List<Texchange> tes = dao.find(data.toString(), params, ex.getPage(), ex.getRows()); List<Exchange> es = new ArrayList<Exchange>(); for (int i = 0; i < tes.size(); i++) { Texchange te = tes.get(i); Exchange e = new Exchange(); BeanUtils.copyProperties(te, e); es.add(e); } DataGrid dataGrid = new DataGrid(); dataGrid.setRows(es); dataGrid.setTotal(dao.count(count, params)); return dataGrid; } catch (Exception e) { e.printStackTrace(); } return null; }
(3)数据:
{ "rows": [ { "consignee": "个广告", "consigneeAddress": "安徽çœå®‰åº†å¸‚枞阳县ggg", "consigneeTel": "18365409608", "datetime": "2016-01-13 23:07:34", "exchangeNum": 134, "id": 3, "isValid": true, "productId": 1, "productName": "前列腺按摩", "userId": 21, "userName": "yamadv" } }
2、HashMap
////HashMap<String, Object>的组织数据
(1)action:
int typeId = Integer.parseInt(this.getRequest().getParameter("typeId")); List<Tactivityslide> plist = this.activitySlideService.getAllActivitySlide(typeId); JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); for (int i = 0; i < plist.size(); i++) { Tactivityslide ta = plist.get(i); jsonObject.clear(); jsonObject.put("id", ta.getId()); jsonObject.put("name", ta.getActivityName()); jsonObject.put("imgUrl", ta.getImgUrl()); int tieId = ta.getTargetId(); jsonObject.put("targetId", tieId); if (typeId == 2) { Tfatie t = bbsService.getSingleFaTie(tieId).get(0); jsonObject.put("theme", t.getTheme()); jsonObject.put("content", t.getContent()); jsonObject.put("fatieTime", t.getFatieTime()); try { String imgurls = ""; List<Ttieziimg> tbi = this.bbsService.getTieImagesByTieId(t.getId()); if (tbi.size() == 0) { jsonObject.put("imgUrls", "no"); } else { for (int j = 0; j < tbi.size(); j++) { if (j == tbi.size() - 1) { imgurls += tbi.get(j).getTieImg(); } else { imgurls += tbi.get(j).getTieImg() + ","; } } jsonObject.put("imgUrls", imgurls); } } catch (Exception e) { e.printStackTrace(); } try { Tuser u = this.userService.getSingleUser(t.getUserId()).get(0); jsonObject.put("userId", u.getId()); jsonObject.put("nickName", u.getNickName()); jsonObject.put("userLever", u.getCommuniteAccess()); jsonObject.put("headImgUrl", u.getHeaderImgUrl()); } catch (Exception e) { e.printStackTrace(); } } jsonArray.add(jsonObject); } HashMap<String, Object> jsMap = new HashMap<String, Object>(); jsMap.put("rows", jsonArray); this.JSObj = JSONObject.fromObject(jsMap); this.writeJson(JSObj);
相关文章推荐
- Spring核心IOC容器实现分析
- ubuntu eclipse菜单栏消失的解决
- ubuntu eclipse启动报错
- Mybatis学习(4)与spring3集成
- weka+eclipse算法二次开发(2)
- java代码创建文件和文件夹
- JAVA系列(2)-JVM
- 学习Java技术Eclipse版本的选择
- JAVA系列(1)
- Java多线程编程
- 用 IntelliJ IDEA 15.x 创建并发布JavaWeb项目
- Spring+Maven+Dubbo+MyBatis+Linner+Handlebars—企业化Web开发环境搭建
- 如何利用Java获取进程的信息(通过tasklist和cmd与Windows进行交互)
- java加密、解密技术系列:Base64
- 怎样学习java?
- 利用sort函数对数组进行排序【java】
- Android生存指南:Eclipse快捷键
- Java集合框架详解
- 解决 java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options?
- Java读写文件