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

来源:互联网 发布:减肥饮品知乎 编辑:程序博客网 时间:2024/06/05 10:51

上一次做了从数据库取文章,可是有的文章穿插着图片,这次就解决这个问题。
我的解决方法是直接在文章中写上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.0admin:哦 发布于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";}