@RequestMapping(value = "/messages/{id}", method = RequestMethod.GET) public String messageViewGet(HttpServletRequest request, @PathVariable Long id, Model model) { Message message = messageService.findOne(id); message.setRead(true); messageService.save(message); model.addAttribute("message", message); return "messages/message"; }
@RequestMapping(value = "/message", method = RequestMethod.POST) public String messageViewPost( HttpServletRequest request, @ModelAttribute("message") Message message, Model model) { User sender = (User) request.getSession().getAttribute("user"); User receiver = userService.findOne(Long.parseLong(request.getParameter("receiver_id"))); message.setSender(sender); message.setReceiver(receiver); message.setSendTime((new Date()).getTime()); try { Ad relevantAd = adService.findOne(Long.parseLong(request.getParameter("ad_id"))); message.setRelevantAd(relevantAd); } catch (Exception e) { System.out.println(e.getMessage()); } messageService.save(message); model.addAttribute("receiver", receiver); return "messages/success"; }