/** 下订单时获取用于的发货地址列表 */ @Override public JSONArray getUserAddress(HttpSession session, Integer kind) { String userId = (String) session.getAttribute(Constant.USER_ID); String hql = "from Address t where t.clientId=:clientId and t.kind=:kind"; Map<String, Object> params = new HashMap<String, Object>(); params.put("clientId", userId); params.put("kind", kind); List<Address> addressList = addressDao.find(hql, params); JSONArray jsonArray = new JSONArray(); for (Address address : addressList) { JSONObject jsonObject = (JSONObject) JSONObject.toJSON(address); jsonArray.add(jsonObject); } return jsonArray; }
/** 获取发货地址 */ @Override public String getAddress(HttpSession session, PageUtil pageUtil, Address address) { String userId = (String) session.getAttribute(Constant.USER_ID); String hql = "from Address t where t.clientId=:clientId and t.kind=:kind order by t.relDate desc "; // 1为发货地址,2为收货地址 Map<String, Object> params = new HashMap<String, Object>(); params.put("clientId", userId); params.put("kind", address.getKind()); int page = pageUtil.getCurrentPage() == 0 ? 1 : pageUtil.getCurrentPage(); int display = pageUtil.getDisplay() == 0 ? 10 : pageUtil.getDisplay(); List<Address> addressList = addressDao.find(hql, params, page, display); JSONArray jsonArray = new JSONArray(); for (Address addr : addressList) { JSONObject jsonObject = (JSONObject) JSONObject.toJSON(addr); jsonArray.add(jsonObject); } return jsonArray.toString(); }