@RequestMapping("/self/message/list") public String listMessage( String type, Integer pageNum, Integer pageSize, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { User user = getCurrentUser(); EntityView ev = new EntityView(); Boolean sendbox = false; if (StringUtils.isNotBlank(type) && type.equals("send")) { sendbox = true; ev.add(Restrictions.eq("sender", user.getUserId())); } else { ev.add(Restrictions.eq("receiver", user.getUserId())); } PageContext<Message> pageCtx = messageMng.queryUsePage(ev, pageNum, 10); model.addAttribute("pageCtx", pageCtx); model.addAttribute("sendbox", sendbox); return "self/message/list"; }
@RequestMapping("/self/profile") public String profile(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { User user = getCurrentUser(); user = userMng.findById(user.getUserId()); List<City> citys = cityMng.findAll(); model.addAttribute("citys", citys); model.addAttribute("userId", user.getUserId()); model.addAttribute("user", user); return "self/profile"; }
@RequestMapping("/self/item/add") public String addItem( Item item, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { String[] picUrls = request.getParameterValues("picUrl"); String[] picUrlSmalls = request.getParameterValues("picUrlSmall"); User user = getCurrentUser(); item.setUserId(user.getUserId()); item.setNickName(user.getNickName()); item.setEmail(user.getEmail()); item.setCreateDate(DateUtils.now()); Integer itemId = itemMng.add(item); for (int i = 0; i < picUrls.length; i++) { ItemPic itemPic = new ItemPic(); itemPic.setItemId(itemId); itemPic.setCreateDate(DateUtils.now()); itemPic.setPicUrl(picUrls[i]); itemPic.setPicUrlSmall(picUrlSmalls[i]); itemPicMng.add(itemPic); } return "redirect:/self"; }
@RequestMapping("/self") public String index( Integer pageNum, Integer pageSize, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { User user = getCurrentUser(); user = userMng.findById(user.getUserId()); EntityView ev = new EntityView(); ev.add(Restrictions.eq("userId", user.getUserId())); PageContext<Item> pageCtx = itemMng.queryUsePage(ev, pageNum, 6); model.addAttribute("pageCtx", pageCtx); model.addAttribute("user", user); return "self/index"; }
@RequestMapping("/self/collection") public String collect( Integer pageNum, Integer pageSize, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { User user = getCurrentUser(); user = userMng.findById(user.getUserId()); PageContext pageCtx = collectionMng.findByUserId(user.getUserId(), pageNum, pageSize); List<Integer> ids = new ArrayList(); List<Collection> collections = pageCtx.getItemList(); for (Collection collection : collections) { ids.add(collection.getItemId()); } Map<String, Item> itemMap = itemMng.getMapByIds(ids); model.addAttribute("pageCtx", pageCtx); model.addAttribute("itemMap", itemMap); model.addAttribute("user", user); return "self/collection"; }
@RequestMapping("/self/message/{id}") public String messageDetail( @PathVariable("id") Integer id, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { Message message = messageMng.findById(id); User user = getCurrentUser(); if (!message.getSender().equals(user.getUserId())) { model.addAttribute("replyAble", true); } model.addAttribute("message", message); return "self/message/detail"; }