您好,登錄后才能下訂單哦!
這篇“Java怎么實現生活旅行分享平臺”文章的知識點大部分人都不太理解,所以小編給大家總結了以下內容,內容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“Java怎么實現生活旅行分享平臺”文章吧。
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
Springboot+ SpringMVC + JPA+ Jsp + Html+ JavaScript + JQuery + Ajax + maven等等
評論業務控制器:
/** * 評論控制器 * @author yy * */ @RestController @RequestMapping("/comment") public class CommentController { @Resource private CommentService commentService; @Resource 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 */ @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(); 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"); 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; } }
回復業務控制器:
/** * 回復控制器 * @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); return resultMap; } /** * 添加回復 * @param reply * @return */ @RequestMapping("/add") public Map<String, Object> add(Reply reply, HttpSession session) { User currentUser = (User) session.getAttribute("user"); Map<String, Object> resultMap = new HashMap<String, Object>(); reply.setReplyDate(new Date()); reply.setUser(currentUser); replyService.add(reply); resultMap.put("reply", reply); resultMap.put("success", true); return resultMap; } }
管理員業務控制器:
/** * 管理員控制器 * @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 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) { mav.addObject("errorInfo", "用戶名或者密碼錯誤!"); mav.setViewName("/login"); } else { session.setAttribute("adminUser", resultUser); // 統計用戶總數 Long userCount = userService.getCount(); // 統計今天注冊 Long userRegCount = userService.getTodayRegistCount(new User(), "1", "1"); // 統計今日登錄 Long userLogCount = userService.getCount(new User(), "1", "1"); // 統計筆記總數 Long artCount = articleService.getCount(); // 統計筆記分類 Long classCount = classifyService.getCount(); session.setAttribute("userCount", userCount); session.setAttribute("userRegCount", userRegCount); session.setAttribute("userLogCount", userLogCount); session.setAttribute("artCount", artCount); session.setAttribute("classCount", classCount); mav.addObject("success", true); mav.setViewName("/admin/index"); } } catch (Exception e) { // 用戶名密碼錯誤 e.printStackTrace(); mav.addObject("admin", admin); mav.addObject("errorInfo", "用戶名或者密碼錯誤!"); mav.setViewName("/login"); } return mav; } /** * 查看個人信息 * * @return */ @RequestMapping("viewPerson") public ModelAndView viewPerson(HttpServletRequest request) { Admin admin = (Admin) request.getSession().getAttribute("adminUser"); ModelAndView mav = new ModelAndView(); Admin u = adminService.findById(admin.getAdminId()); mav.addObject("user", u); mav.setViewName("/admin/adminViewPerson"); 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("/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; } /** * 分頁查詢用戶 * @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]; } 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); 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 * @param userId * @return */ @RequestMapping("/addFocusUser") public ModelAndView addFocusUser(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.add(userId); String ret = StringUtils.join(lineIdList, ","); user.setUserIds(ret); userService.save(user); mav.setViewName("redirect:/viewFocusUser"); return mav; } @RequestMapping("/addFocusUser/{userId}") public ModelAndView addFocusUser(@PathVariable(value = "userId", required = false) Integer userId, HttpSession session) { ModelAndView mav = new ModelAndView(); User user = (User) session.getAttribute("user");// 當前登錄用戶 String userIds = user.getUserIds(); List<String> tempList = new ArrayList<>(); if (userIds != null) { tempList = Arrays.asList(userIds.split(",")); } List<String> lineIdList = new ArrayList<>(tempList); lineIdList.add(userId.toString()); String ret = StringUtils.join(lineIdList, ","); user.setUserIds(ret); userService.save(user); mav.setViewName("redirect:/viewFocusUser"); return mav; } /** * 取消收藏 * @param request * @param userId * @return */ @RequestMapping("/removeCollection") public ModelAndView removeCollection(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.remove(artId); String ret = StringUtils.join(lineIdList, ","); user.setArticleIds(ret); userService.save(user); mav.setViewName("redirect:/viewCollection"); return mav; } /** * 收藏 * @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; } }
以上就是關于“Java怎么實現生活旅行分享平臺”這篇文章的內容,相信大家都有了一定的了解,希望小編分享的內容對大家有幫助,若想了解更多相關的知識內容,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。