兴致很高,趁着劲头把用户界面也做起来
<body align="center">
<h3 th:text="${Username}">用户名</h3>
<hr/>
<div th:each="cs:${Comments}">
<p th:text="${cs.comtime}">时间</p>
<p th:utext="${cs.nid}">新闻</p>
<p th:utext="${cs.context}">内容</p>
</div>
</body>
很简陋,只有评论。
@RequestMapping(value = "/{id}",method = RequestMethod.GET)
public String toUserById(@PathVariable("id") String id,ModelMap map){
map.addAttribute("Username",userService.getUsernameById(Integer.valueOf(id)));
List<Comment> comments = commentService.getAllCommentByUid((id));
Collections.reverse(comments);
for(int i=0;i<comments.size();i++){
int nid = Integer.valueOf(comments.get(i).getNid());
String titleWithUrl = "<a href =\"../" + nid + "\">" + newsService.getNewsTitleById(nid) + "</a>";
comments.get(i).setNid(titleWithUrl);
//判断是否是回复,做出处理
String tid = comments.get(i).getTid();
if(tid == null || tid == "") {
//什么都不做
}else {
String tName = userService.getUsernameById(Integer.valueOf(comments.get(i).getTid()));
comments.get(i).setContext("回复<a href =\"../user/" + tid + "\">@" + tName + "</a> :" + comments.get(i).getContext());
}
}
map.addAttribute("Comments",comments);
return "user";
}
好臃肿的代码……
把超链接直接写到属性里传过去了。
同理把新闻的Conrtoller也修改下。
comments.get(i).setUid("<a href =\"user/" + uid + "\">" + uName + "</a> :");
comments.get(i).setTid("回复<a href =\"user/" + tid + "\">@" + tName + "</a> :");
感觉接下来只有各种增删改查了呢:)