BBSController { @Secured("ROLE_USER") @GetMapping("showmessage") public String showMessage( @RequestParam("message_id") long messageId, Model model) { Message message = messageMapper.findOne(messageId); if (message == null) { throw new BusinessException(BusinessCode.MESSAGE_NOT_FOUND); } final DateTimeFormatter formatter = dtf.withZone(ZoneId.systemDefault()); final Instant inDate = message.getInDate(); final Long parentId = message.getParent(); final String uid = message.getUser(); final String title = message.getTitle(); final Long pid = message.getProblem(); final long depth = message.getDepth() + 1; final long thread = message.getThread(); final long order = message.getOrder(); model.addAttribute("title", "Detail of message"); StringBuilder sb = new StringBuilder("<table border=\"0\" width=\"980\" class=\"table-back\">" + "<tr><td>" + "<center><h2><font color=\"blue\">") .append(HtmlEscape.escapeHtml4Xml(title)) .append("</font></h2></center>" + "Posted by <b><a href=\"userstatus?user_id=") .append(uid).append("\"><font color=\"black\">") .append(uid).append("</font></a></b>" + "at ") .append(formatter.format(inDate)); if (pid != null && pid != 0) { sb.append("on <b><a href=\"showproblem?problem_id=").append(pid) .append("\"><font color=\"black\">Problem ").append(pid) .append("</font></a></b>"); } if (parentId != null && parentId != 0) { Message parent = messageMapper.findOne(parentId); if (parent != null) { String title1 = parent.getTitle(); Instant inDate1 = parent.getInDate(); sb.append("<br/>In Reply To:<a href=\"showmessage?message_id=") .append(parentId).append("\"><font color=\"blue\">").append(HtmlEscape.escapeHtml4Xml(title1)).append("</font></a>" + "Posted by:<b><a href=\"userstatus?user_id=").append(parent.getUser()).append("\"><font color=\"black\">").append(parent.getUser()).append("</font></a></b>" + "at ").append(formatter.format(inDate1)); } } sb.append("<HR noshade color=#FFF><pre>"); sb.append(HtmlEscape.escapeHtml4Xml(message.getContent())); sb.append("</pre><HR noshade color=\"#FFF\"><b>Followed by:</b><br/><ul>"); long dep = depth; List<Message> messages = messageMapper.findAllByThreadIdAndOrderNumGreaterThanOrderByOrderNum(thread, order); for (Message m : messages) { String user = m.getUser(); long id = m.getId(); String title1 = m.getTitle(); Instant inDate1 = m.getInDate(); final long depth1 = m.getDepth(); if (depth1 < depth) { break; } for (long i = dep; i < depth1; ++i) { sb.append("<ul>"); } for (long i = depth1; i < dep; i++) { sb.append("</ul>"); } sb.append("<li><a href=\"showmessage?message_id=") .append(id).append("\"><font color=\"blue\">") .append(HtmlEscape.escapeHtml4Xml(title1)) .append("</font></a>" + " -- <b><a href=\"userstatus?user_id=") .append(user) .append("\"><font color=\"black\">") .append(user) .append("</font></a></b> "); sb.append(formatter.format(inDate1)); dep = depth1; } for (long i = depth; i < dep; ++i) { sb.append("</ul>"); } sb.append("</ul>" + "<HR noshade color=\"#FFF\">" + "<font color=\"blue\">Post your reply here:</font><br/>" + "<form method=\"POST\" action=\"post\">"); if (pid != null) { sb.append("<input type=\"hidden\" name=\"problem_id\" value=\"").append(pid).append("\"/>"); } sb.append("<input type=\"hidden\" name=\"parent_id\" value=\"").append(messageId).append("\"/>"); sb.append("Title:<br/><input type=\"text\" name=\"title\" value=\"") .append(HtmlEscape.escapeHtml4Xml(!title.regionMatches(true, 0, "re:", 0, 3) ? "Reply:" + title : title)) .append("\" size=75><br/>" + "Content:<br/><textarea rows=\"15\" name=\"content\" cols=\"75\">") .append(JudgeUtils.INSTANCE.getReplyString(message.getContent())) .append("</textarea><br/><button type=\"submit\">reply</button></td></tr></table>"); model.addAttribute("content", sb.toString()); return "legacy"; }  @GetMapping("bbs") String bbs(HttpServletRequest request,
            @RequestParam(value = "problem_id", required = false) Long problemId,
            @RequestParam(value = "size", defaultValue = "50") final int threadLimit,
            @RequestParam(value = "top", defaultValue = "99999999") final long top,
            Model model); @Secured("ROLE_USER") @GetMapping({"postpage", "post"}) String postpage(Model model,
            @RequestParam(value = "problem_id", required = false) Long problemId); @PostMapping("post") @Secured("ROLE_USER") @Transactional String post(@RequestParam(value = "problem_id", required = false) Long problemId,
            @RequestParam(value = "parent_id", required = false) Long parentId,
            @RequestParam(value = "content", defaultValue = "") String content,
            @RequestParam(value = "title", defaultValue = "") String title,
            RedirectAttributes redirectAttributes,
            Authentication authentication); @Secured("ROLE_USER") @GetMapping("showmessage") String showMessage(
            @RequestParam("message_id") long messageId,
            Model model);  }
@Test public void testShowMessage() throws Exception { log.info("showMessage"); String userId = createUser(); long messageId = messageMapper.nextId(); messageService.save(null, null, userId, "title", "content"); mvc.perform(get("/showmessage").with(user(userId)) .param("message_id", Long.toString(messageId))) .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)) .andReturn(); }