您的位置:首页 > 其它

做毕设(三)——用户界面

2017-09-01 20:05 22 查看
兴致很高,趁着劲头把用户界面也做起来

<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> :");


感觉接下来只有各种增删改查了呢:)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: