@RequestMapping("edit-message") public String editMessage(Integer id, String message) { Message messageText = messages.findOne(id); messageText.message = message; if (message == "") { } else messages.save(messageText); return "redirect:/"; }
@RequestMapping("add-message") public String addMessage(String message) { Message messageText = new Message(); messageText.message = message; messages.save(messageText); return "redirect:/"; }
@RequestMapping("/") public String home(Model model, HttpServletRequest request) { HttpSession session = request.getSession(); String username = (String) session.getAttribute("username"); model.addAttribute("username", username); model.addAttribute( "messages", messages .findAll()); // we call findAll() because it's a list of things instead of the // "messages" repository above. return "home"; }
@RequestMapping("delete-message") public String deleteMessage(Integer id) { // Message messageText = messages.findOne(id); messages.delete(id); return "redirect:/"; }