做毕设(二)——跳转和评论

xiaoxiao2021-02-28  141

上一次做了从数据库取文章,可是有的文章穿插着图片,这次就解决这个问题。 我的解决方法是直接在文章中写上html标签。 但是会发现<>在源代码中被转义字符替代,在页面上依然是<img scr="image/a.jpg"> 后来发现用th:utext 即可。


接着实现新闻的评论

<div th:each="cs:${Comments}"> <p th:text="${cs.uid}+${cs.tid}+${cs.context}+'发布于'+${cs.comtime}">暂无评论</p> </div> /* 效果: aaa回复@:admin否 发布于2017-09-01 09:41:17.0 admin:哦 发布于2017-09-01 13:08:48.0 */ @RequestMapping(value = "/{id}",method = RequestMethod.GET) public String toNewsById(@PathVariable("id") String id,ModelMap map){ map.addAttribute("News",newsService.getNewsById(Integer.valueOf(id))); List<Comment> comments = commentService.getAllCommentByNid((Integer.valueOf(id))); Collections.reverse(comments); for(int i=0;i<comments.size();i++){ //将id换成用户名 String uid = comments.get(i).getUid(); String uName = userService.getUsernameById(Integer.valueOf(uid)); comments.get(i).setUid(uName); //判断是否是回复,做出处理 String tid = comments.get(i).getTid(); if(tid == null || tid == "") { //不是回复的话用来当“:” comments.get(i).setTid(":"); }else { String tName = userService.getUsernameById(Integer.valueOf(tid)); comments.get(i).setTid("回复@:" + tName); } } map.addAttribute("Comments",comments); return "newspage"; }
转载请注明原文地址: https://www.6miu.com/read-77011.html

最新回复(0)