一、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
Springboot+ SpringMVC + JPA+ Jsp + Html+ JavaScript + JQuery + Ajax + maven等等
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
* @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
mav.setViewName("redirect:/viewCollection");
return mav;
}
}
评论业务控制器:
/**
* 评论控制器
* @author yy
*
*/
@RestController
@RequestMapping("/comment")
public class CommentController {
@Resource
private CommentService commentService;
@Resource
private ArticleService articleService;
@Resource
private ReplyService replyService;
/**
@Resource
private UserService userService;
@Resource
private ArticleService articleService;
@Resource
private ClassifyService classifyService;
/**
* 后台管理员登录验证
* @param admin
* @param request
* @return
*/
@RequestMapping("/login")
public ModelAndView login(Admin admin, HttpServletRequest request) {
ModelAndView mav = new ModelAndView();
HttpSession session = request.getSession();
try {
Admin resultUser = adminService.findByUserNameAndPassword(admin.getUserName(), admin.getPassword());
if (resultUser == null) {
/**
* 管理员控制器
* @author yy
*
*/
@RestController
@RequestMapping("/admin")
public class AdminController {
@Value("${MD5Salt}")
private String salt; // md5加密盐
@Resource
private AdminService adminService;
@Resource
private UserService userService;
@Resource
private ArticleService articleService;
@Resource
if (comment.getArticle() != null) {
articleService.increaseComment(comment.getArticle().getArticleId());
}
resultMap.put("comment", comment);
resultMap.put("success", true);
return resultMap;
}
}
回复业务控制器:
/**
* 回复控制器
* @author yy
*
*/
@RestController
@RequestMapping("/reply")
public class ReplyController {
@Resource
private ReplyService replyService;
/**
* 获取回复
* @param reply
* @return
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
*/
@RequestMapping("/massageList")
public Map<String, Object> massageList(@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
List<Comment> commentList = commentService.massageList(page - 1, pageSize);
Long total = commentService.getCount2();
@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];
}
List<User> userList = userService.list(user, s_bregistrationDate, s_eregistrationDate, page - 1, pageSize);
Long total = userService.getCount(user, s_bregistrationDate, s_eregistrationDate);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("errorNo", 0);
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);
用户业务控制器:
/**
* 用户控制器
*
*/
@RestController
@RequestMapping("/admin/user")
public class UserAdminController {
@Resource
private UserService userService;
@Value("${MD5Salt}")
private String salt; // md5加密盐
/**
* 根据ID查找用户
* @param userId
* @return
*/
@RequestMapping("/findById")
*
*/
@RestController
@RequestMapping("/admin/user")
public class UserAdminController {
@Resource
private UserService userService;
@Value("${MD5Salt}")
private String salt; // md5加密盐
/**
* 根据ID查找用户
* @param userId
* @return
*/
@RequestMapping("/findById")
public Map<String, Object> findById(Integer userId) {
Map<String, Object> resultMap = new HashMap<String, Object>();
User user = userService.findById(userId);
resultMap.put("errorNo", 0);
resultMap.put("data", user);
return resultMap;
}
resultMap.put("comment", comment);
resultMap.put("success", true);
return resultMap;
}
}
回复业务控制器:
/**
* 回复控制器
* @author yy
*
*/
@RestController
@RequestMapping("/reply")
public class ReplyController {
@Resource
private ReplyService replyService;
/**
* 获取回复
* @param reply
* @return
*/
@RequestMapping("/list")
public Map<String, Object> replyList(Reply reply) {
List<Reply> replyList = replyService.list(reply);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("data", replyList);