【发布时间】:2018-05-07 19:06:15
【问题描述】:
我正在启动一个允许用户通过其内容获利的应用程序。我根据页面上的查看次数来确定赚到的金额,因此该页面需要一种经过验证的方式来计算查看次数。据我所知,让一个用户只能增加一次查看计数器(就像 YouTube 视频一样)的最佳方法是使用 Session Requests 或 IP Adresses.
这是我的控制器:
@RequestMapping("/viewPhoto/{id}")
public String viewPhoto(@PathVariable int id, Model model) {
Photo photo = photoService.getPhotoById(id);
//irrelevant code
Long commentNumber = commentService.getCommentNumber(id); //number of comments
List<Comment> commentList = commentService.getComments(); //getting comments
List<Reply> replyList = commentService.getRepliesByComment(); //getting replies for each comment
model.addAttribute("replyList", replyList);
model.addAttribute("commentList", commentList);
model.addAttribute("photo", photo);
model.addAttribute("commentNumber", commentNumber);
//if the viewer is valid and hasn't viewed the photo, increment view count
return "viewPhoto";
}
如果我使用@SessionAttribute 检索会话对象,我如何使用它来验证视图是否唯一?
对不起,如果这是一个菜鸟问题。
提前谢谢你!
【问题讨论】:
标签: java spring validation session model-view-controller