文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Java毕业设计实战之生活旅行分享平台的实现

2024-04-02 19:55

关注

一、项目运行

环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

Springboot+ SpringMVC + JPA+ Jsp + Html+ JavaScript + JQuery + Ajax + maven等等

评论业务控制器:



@RestController
@RequestMapping("/comment")
public class CommentController {
 
  @Resource
  private CommentService commentService;
 
  @Resource
  private ArticleService articleService;
 
  @Resource
  private ReplyService replyService;
 
  
  @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;
  }
 
  
  @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;
  }
 
  
  @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;
  }
 
}

回复业务控制器:



@RestController
@RequestMapping("/reply")
public class ReplyController {
 
  @Resource
  private ReplyService replyService;
 
  
  @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;
  }
 
  
  @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;
  }
 
}

管理员业务控制器:



@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;
 
  
  @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;
  }
 
  
  @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;
  }
 
  
  @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加密盐
 
  
  @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;
  }
 
  
  @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;
  }
 
  
  @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;
  }
 
  
  @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;
  }
 
  
  @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;
  }
 
  
  @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毕业设计实战之生活旅行分享平台的实现的文章就介绍到这了,更多相关Java 生活旅行分享平台内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯