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

 更新时间:2022年02月05日 12:49:19   作者:qq_1334611189  
这是一个使用了java+Springboot+JPA+Jsp+Html+js+Ajax+maven+mysql开发的生活旅行分享平台,是一个毕业设计的实战练习,具有分享发布平台该有的所有功能,感兴趣的朋友快来看看吧

一、项目运行

环境配置:

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

相关文章

  • Feign如何解决服务之间调用传递token

    Feign如何解决服务之间调用传递token

    这篇文章主要介绍了Feign如何解决服务之间调用传递token,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-03-03
  • IDEA编写JavaWeb出现乱码问题解决方案

    IDEA编写JavaWeb出现乱码问题解决方案

    这篇文章主要介绍了IDEA编写JavaWeb出现乱码问题解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-09-09
  • Java生产1-100的随机数简单实例(分享)

    Java生产1-100的随机数简单实例(分享)

    下面小编就为大家带来一篇Java生产1-100的随机数简单实例(分享)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • 将idea中xml文件背景颜色去除的图文教程

    将idea中xml文件背景颜色去除的图文教程

    这篇文章主要介绍了将idea中xml文件背景颜色去除,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-07-07
  • springboot清除字符串前后空格与防xss攻击方法

    springboot清除字符串前后空格与防xss攻击方法

    这篇文章主要介绍了springboot清除字符串前后空格与防xss攻击方法,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-08-08
  • Java常用的八种排序算法及代码实现+图解

    Java常用的八种排序算法及代码实现+图解

    这篇文章主要介绍了Java常用的八种排序算法及代码实现,在Java的时候,对于排序的应用需要熟练的掌握,这样才能够确保Java学习时候能够有扎实的基础能力。那Java有哪些排序算法呢?本文小编就来详细说说Java经典的8种排序算法,需要的朋友可以参考一下
    2021-12-12
  • Spring+Mybatis 实现aop数据库读写分离与多数据库源配置操作

    Spring+Mybatis 实现aop数据库读写分离与多数据库源配置操作

    这篇文章主要介绍了Spring+Mybatis 实现aop数据库读写分离与多数据库源配置操作,需要的朋友可以参考下
    2017-09-09
  • SpringBoot_Cache自定义使用SimpleCacheManager方式

    SpringBoot_Cache自定义使用SimpleCacheManager方式

    这篇文章主要介绍了SpringBoot_Cache自定义使用SimpleCacheManager方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-07-07
  • 如何基于JAVA读取yml配置文件指定key内容

    如何基于JAVA读取yml配置文件指定key内容

    这篇文章主要介绍了如何基于JAVA读取yml配置文件指定key内容,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-01-01
  • Java冒泡排序的定义与实例代码

    Java冒泡排序的定义与实例代码

    这篇文章主要给大家介绍了关于Java冒泡排序的定义与实例的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-12-12

最新评论