// 根据编号获得团购 @Action( value = "searchGroupon", interceptorRefs = {@InterceptorRef(value = "userActionStack")}, results = {@Result(name = SUCCESS, type = "json")}) public String searchGroupon() { User sessionUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user"); // 获得这个学校所有的团购项目 if (groupon.getName() != null) { // name = CommonUtil.getSortString(name.trim()); name = "%" + groupon.getName() + "%"; } List<Groupon> groupons = grouponService.effectiveGroupons(sessionUser.getSchool().getId(), page, name); List<GrouponBean> grouponBeanList = new ArrayList<>(); for (int i = 0; i < groupons.size(); i++) { GrouponBean bean = new GrouponBean(); bean.setId(groupons.get(i).getId()); bean.setName(groupons.get(i).getName()); bean.setClassNo(groupons.get(i).getClassNo()); bean.setTel(groupons.get(i).getTel()); bean.setEndTime(CommonUtil.dateToString(groupons.get(i).getEndTime())); grouponBeanList.add(bean); } String json = JSONArray.fromObject(grouponBeanList).toString(); PrintWriter writer = CommonUtil.getJsonPrintWriter(ServletActionContext.getResponse()); writer.write(json); writer.flush(); writer.close(); return SUCCESS; }
// 1 进入团购的页面 @Action( value = "grouponPage", interceptorRefs = {@InterceptorRef(value = "userActionStack")}, results = {@Result(name = SUCCESS, location = "/userPages/groupon.jsp")}) public String grouponPage() { User sessionUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user"); // 获得这个学校所有的团购项目 List<Groupon> groupons = grouponService.effectiveGroupons(sessionUser.getSchool().getId(), page, null); ServletActionContext.getContext().getValueStack().set("groupons", groupons); return SUCCESS; }