首页 > 数据库 >Java项目:校园周边美食探索(java+SpringBoot+Mybaits+Vue+elementui+mysql)

Java项目:校园周边美食探索(java+SpringBoot+Mybaits+Vue+elementui+mysql)

时间:2024-05-26 10:34:12浏览次数:14  
标签:Java String userId resultMap user mysql return param SpringBoot

源码获取:俺的博客首页 "资源" 里下载! 

项目介绍

基于Springboot + vue实现的校园周边美食探索及分享平台

本系统包含管理员、用户两个角色。

管理员:用户管理、美食鉴赏管理、好友管理、收藏管理、系统管理

用户:登录、注册、个人中心管理、美食鉴赏管理、好友管理、收藏管理、个人信息管理、美食鉴赏发布与管理


环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
4.数据库:MySql 5.7/8.0版本均可;
5.是否Maven项目:是;


技术栈

后端:SpringBoot+Mybaits

前端:Vue+elementui


使用说明

项目运行:
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入地址:
前台地址:
http://localhost:8080/springboot35l3z/front/index.html
用户: 用户1 密码 123456

后台地址
http://localhost:8080/springboot35l3z/admin/dist/index.html
管理员 abo 密码 123456


注意项目文件路径中不能含有中文、空格、特殊字符等,否则图片会上传不成功。

文档结构展示:

首页页面展示:

首页页面展示:

个人中心页面展示:

我的好友信息展示:

登录页面展示:

美食菜品展示:

我的收藏管理展示:

用户控制器:

/**
 * 用户控制器
 *
 */
@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;
  }
}

评论控制层:

/**
 * 评论Controller层
 *
 */
@RestController
@RequestMapping("/admin/comment")
public class CommentAdminController {

  @Resource
  private CommentService commentService;

  @Resource
  private UserService userService;

  @Resource
  private ReplyService replyService;

  @Resource
  private ArticleService articleService;

  /**
   * 分页查询评论
  * @Title: list  
  * @param comment  评论实体
  * @param commentDates  时间段 (搜索用到)
  * @param page  当前页
  * @param limit  每页记录数
  * @param trueName  昵称
  * @return  参数说明 
  * @return Map<String,Object>    返回类型 
  * @throws
   */
  @RequestMapping("/list")
  public Map<String, Object> list(Comment comment,
      @RequestParam(value = "commentDates", required = false) String commentDates,
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "pageSize", required = false) Integer pageSize,
      @RequestParam(value = "nickname", required = false) String nickname) {
    String s_bCommentDate = null; // 开始时间
    String s_eCommentDate = null; // 结束时间
    if (StringUtil.isNotEmpty(commentDates)) {
      String[] strs = commentDates.split(" - "); // 拆分时间段
      s_bCommentDate = strs[0];
      s_eCommentDate = strs[1];
    }
    Integer userId = null;
    Map<String, Object> resultMap = new HashMap<String, Object>();
    if (StringUtil.isNotEmpty(nickname)) {
      User user = userService.findByTrueName(nickname);
      if (user != null) {
        userId = user.getUserId();
      }
      if (userId == null) {
        resultMap.put("errorInfo", "用户昵称不存在,没有评论!");
      } else {
        resultMap.put("errorNo", 0);
      }
    } else {
      resultMap.put("errorNo", 0);
    }
    List<Comment> commentList = commentService.list(comment, s_bCommentDate, s_eCommentDate, page - 1, pageSize,
        userId);
    Long total = commentService.getCount(comment, s_bCommentDate, s_eCommentDate, userId);
    resultMap.put("data", commentList);
    resultMap.put("total", total);
    return resultMap;
  }

  /**
   * 删除评论
   * @param ids
   * @return
   */
  @RequestMapping("/delete")
  public Map<String, Object> delete(@RequestParam(value = "commentId") String ids) {
    String[] idsStr = ids.split(","); // 拆分ids字符串
    Map<String, Object> resultMap = new HashMap<String, Object>();
    for (int i = 0; i < idsStr.length; i++) {
      Integer articleId = commentService.getArticleId(Integer.parseInt(idsStr[i]));
      commentService.delete(Integer.parseInt(idsStr[i]));
      if (articleId != null) {
        articleService.reduceComment(articleId);
      }
    }
    resultMap.put("errorNo", 0);
    resultMap.put("data", 1);
    return resultMap;
  }

}

回复控制器:

/**
 * 回复控制器
 *
 */
@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;
  }

}

源码获取:俺的博客首页 "资源" 里下载!

标签:Java,String,userId,resultMap,user,mysql,return,param,SpringBoot
From: https://blog.csdn.net/m0_66863468/article/details/139207955

相关文章

  • 基于SpringBoot+Vue的在线商城系统
    !!!有需要的小伙伴可以通过文章末尾名片咨询我哦!!! ......
  • MySQL报错注入之Xpath报错&floor函数报错
    目录前言Xpath报错注入updatexml()函数extractvalue()函数floor函数报错count与groupby的虚拟表总结前言报错注入的使用场景一般是页面无法正常回显数据库查询的内容,但是会详细显示查询过程的错误信息。如果连错误信息都没有,那就是盲注了。报错注入的原理就是将子查询语句查询......
  • 滑不动窗口的秘密—— “滑动窗口“算法 (Java版)
    本篇会加入个人的所谓鱼式疯言❤️❤️❤️鱼式疯言:❤️❤️❤️此疯言非彼疯言而是理解过并总结出来通俗易懂的大白话,小编会尽可能的在每个概念后插入鱼式疯言,帮助大家理解的.......
  • Java虚拟机揭秘-底层驱动力,性能保障!
    Java虚拟机作为Java技术体系的核心组成部分,其重要性不言而喻。它不仅为Java提供了跨平台的能力,更是Java程序运行的基石。本文将为您深入解析Java虚拟机的工作原理、作用和应用场景,并通过生动的实例让您彻底理解这一关键技术。一、Java虚拟机详细介绍1、什么是Java虚拟......
  • MySQL入门——增删查改(下)
    数据库约束约束类型NOTNULL-指示某列不能存储NULL值。UNIQUE-保证某列的每行必须有唯一的值。DEFAULT-规定没有给列赋值时的默认值。PRIMARYKEY-NOTNULL和UNIQUE的结合。确保某列(或两个列多个列的结合)有唯一标识,有助于更容易更快速地找到表中的一个特定的......
  • MySQL函数
    MySQL数据库提供了很多函数包括:数学函数;字符串函数;日期和时间函数;条件判断函数;系统信息函数;加密函数;格式化函数;mysql高级教程:http://cainiao.guashuw.com/一、数学函数数学函数主要用于处理数字,包括整型、浮点数等。函数作用ABS(x)返回x的绝对值......
  • MySQL Grant命令
    MySQL赋予用户权限命令的简单格式可概括为:grant权限on数据库对象to用户 MySQL高级教程:http://cainiao.guashuw.com/一、grant普通数据用户,查询、插入、更新、删除数据库中所有表数据的权利。grantselectontestdb.*tocommon_user@'%'grantinsertontestdb.*......
  • 宠物服务系统 毕业设计 Springboot+Vue+Mysql+Java
    作者主页:毕业设计精选作者简介:9年JAVA全栈开发经验,专注JAVA技术、系统定制、远程指导,致力于企业数字化转型,CSDN博客专家摘要随着人类生存质量的提升以及生活模式的改变,越来越多的人在闲暇之余饲养宠物,来满足精神上的需求 。从而 使得宠物服务行业也得到了繁荣发展 ......
  • MySQL命令大全
    1、连接Mysql格式:mysql-h主机地址-u用户名-p用户密码1、连接到本机上的MYSQL。首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql-uroot-p,回车后提示你输密码.注意用户名前可以有空格也可以没有空格,但是密码前必须没有空格,否则让你重新输入密码。如果刚安装好MYSQL,超级......
  • MySQL权限管理
    一、MySQL权限简介   关于mysql的权限简单的理解就是mysql允许你做你全力以内的事情,不可以越界。比如只允许你执行select操作,那么你就不能执行update操作。只允许你从某台机器上连接mysql,那么你就不能从除那台机器以外的其他机器连接mysql。MySQL高级教程:http://cainiao.guas......