一、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
Springboot+ SpringMVC + JPA+ Jsp + Html+ JavaScript + JQuery + Ajax + maven等等
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
* @param page
* @param pageSize
* @return
*/
@RequestMapping("/list")
public Map<String, Object> commentList(Comment comment, @RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
List<Comment> commentList = commentService.list(comment, null, null, page - 1, pageSize, null);
Long total = commentService.getCount(comment, null, null, null);
int totalPage = (int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("totalPage", totalPage);
resultMap.put("data", commentList);
return resultMap;
}
private ArticleService articleService;
@Resource
private ReplyService replyService;
/**
* 分页查询评论
* @param comment
* @param page
* @param pageSize
* @return
*/
@RequestMapping("/list")
public Map<String, Object> commentList(Comment comment, @RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
List<Comment> commentList = commentService.list(comment, null, null, page - 1, pageSize, null);
Long total = commentService.getCount(comment, null, null, null);
int totalPage = (int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("totalPage", totalPage);
resultMap.put("data", commentList);
return resultMap;
}
/**
* 分页查询评论
* @param page
* @param pageSize
* @return
*/
User user = userService.findById(userId);
resultMap.put("errorNo", 0);
resultMap.put("data", user);
return resultMap;
}
/**
* 分页查询用户
* @param user
* @param registrationDates
* @param page
* @param limit
* @return
*/
@RequestMapping("/list")
public Map<String, Object> list(User user,
@RequestParam(value = "latelyLoginTimes", required = false) String latelyLoginTimes,
@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
String s_bregistrationDate = null; // 开始时间
String s_eregistrationDate = null; // 结束时间
if (StringUtil.isNotEmpty(latelyLoginTimes)) {
String[] strs = latelyLoginTimes.split(" - "); // 拆分时间段
s_bregistrationDate = strs[0];
s_eregistrationDate = strs[1];
return mav;
}
/**
* 保存用户信息
*
* @param user
* @return
*/
@RequestMapping("/save")
public ModelAndView save(Admin user) {
ModelAndView mav = new ModelAndView();
adminService.save(user);
mav.setViewName("/admin/index");
return mav;
}
}
用户业务控制器:
/**
* 用户控制器
*
*/
@RestController
@RequestMapping("/add")
public Map<String, Object> add(Comment comment, HttpSession session) {
User currentUser = (User) session.getAttribute("user");
Map<String, Object> resultMap = new HashMap<String, Object>();
comment.setCommentDate(new Date());
comment.setUser(currentUser);
commentService.add(comment);
if (comment.getArticle() != null) {
articleService.increaseComment(comment.getArticle().getArticleId());
}
resultMap.put("comment", comment);
resultMap.put("success", true);
return resultMap;
}
}
回复业务控制器:
/**
* 回复控制器
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
List<Comment> commentList = commentService.massageList(page - 1, pageSize);
Long total = commentService.getCount2();
int totalPage = (int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("totalPage", totalPage);
resultMap.put("data", commentList);
return resultMap;
}
/**
* 添加评论
* @Title: add
* @param comment 评论实体
* @return 参数说明
* @return Map<String,Object> 返回类型
* @throws
*/
@RequestMapping("/add")
public Map<String, Object> add(Comment comment, HttpSession session) {
User currentUser = (User) session.getAttribute("user");
}
/**
* 取消关注
* @param request
* @param userId
* @return
*/
@RequestMapping("/removeFocusUser")
public ModelAndView removeFocusUser(HttpServletRequest request, String userId) {
ModelAndView mav = new ModelAndView();
User user = (User) request.getSession().getAttribute("user");// 当前登录用户
String userIds = user.getUserIds();
List<String> tempList = Arrays.asList(userIds.split(","));
List<String> lineIdList = new ArrayList<>(tempList);
lineIdList.remove(userId);
String ret = StringUtils.join(lineIdList, ",");
user.setUserIds(ret);
userService.save(user);
mav.setViewName("redirect:/viewFocusUser");
resultMap.put("data", userList);
resultMap.put("total", total);
return resultMap;
}
@RequestMapping("/delete")
public Map<String, Object> delete(Integer userId) {
Map<String, Object> resultMap = new HashMap<String, Object>();
userService.delete(userId);
resultMap.put("errorNo", 0);
return resultMap;
}
/**
* 取消关注
* @param request
* @param userId
* @return
*/
@RequestMapping("/removeFocusUser")
public ModelAndView removeFocusUser(HttpServletRequest request, String userId) {
ModelAndView mav = new ModelAndView();
User user = (User) request.getSession().getAttribute("user");// 当前登录用户
String userIds = user.getUserIds();
List<String> tempList = Arrays.asList(userIds.split(","));
List<String> lineIdList = new ArrayList<>(tempList);
lineIdList.remove(userId);
String ret = StringUtils.join(lineIdList, ",");
* 收藏
* @param request
* @param userId
* @return
*/
@RequestMapping("/addCollection")
public ModelAndView addCollection(HttpServletRequest request, String artId) {
ModelAndView mav = new ModelAndView();
User user = (User) request.getSession().getAttribute("user");// 当前登录用户
String artIds = user.getArticleIds();
List<String> tempList = Arrays.asList(artIds.split(","));
List<String> lineIdList = new ArrayList<>(tempList);
lineIdList.add(artId);
String ret = StringUtils.join(lineIdList, ",");
user.setArticleIds(ret);
userService.save(user);
mav.setViewName("redirect:/viewCollection");
return mav;
}
}
评论业务控制器:
/**
* 评论控制器
* @author yy
*
*/
@RestController
userService.delete(userId);
resultMap.put("errorNo", 0);
return resultMap;
}
/**
* 取消关注
* @param request
* @param userId
* @return
*/
@RequestMapping("/removeFocusUser")
public ModelAndView removeFocusUser(HttpServletRequest request, String userId) {
ModelAndView mav = new ModelAndView();
User user = (User) request.getSession().getAttribute("user");// 当前登录用户
String userIds = user.getUserIds();
List<String> tempList = Arrays.asList(userIds.split(","));
List<String> lineIdList = new ArrayList<>(tempList);
lineIdList.remove(userId);
String ret = StringUtils.join(lineIdList, ",");
user.setUserIds(ret);
userService.save(user);
mav.setViewName("redirect:/viewFocusUser");
return mav;
}
/**
* 关注用户
* @param request