1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Java项目:零食商城系统(java+JSP+JavaScript+servlet+Mysql)

Java项目:零食商城系统(java+JSP+JavaScript+servlet+Mysql)

时间:2020-12-07 09:10:28

相关推荐

Java项目:零食商城系统(java+JSP+JavaScript+servlet+Mysql)

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

项目介绍

本项目分前后台,共有管理员、卖家、买家三种角色;

前台主要功能包括:

首页、商城介绍、商品一览、打折专区、销售排行、成交记录、商城资讯、联系我们、留言板等功能;

管理员主要功能包括:

交易信息查看:进行中的订单、历史订单;

网站信息查看与编辑:商城介绍、商城资讯、广告图片、联系我们、商城公告、留言板、友情链接等;

基础信息查看与编辑:买家会员、卖家会员、商品管理、商品评价管理、商品属性设置;

系统管理:添加管理员、管理员维护;

个人信息:基本资料管理、修改登录密码;

卖家主要功能包括:

交易信息查看:查看订单、历史订单;

商品管理:添加商品、商品管理;

商铺信息:基本资料管理、修改登录密码;

买家主要功能包括:

登录前台、买家中心、交易信息查看(查看订单、历史订单、购物车)、个人信息;

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。

2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;

3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可

4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;

5.数据库:MySql 5.7版本;

6.是否Maven项目:否;

技术栈

1. 后端:Servlet

2. 前端:JSP+CSS+JavaScript+ajax

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;

3. 将项目中dbconnection.properties配置文件中的数据库配置改为自己的配置;

4. 运行项目,输入http://localhost:8080/foodemarket 登录

用户控制器:

/*** 用户控制器**/@RestController@RequestMapping("/admin/user")public class UserAdminController {@Resourceprivate 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 {@Resourceprivate CommentService commentService;@Resourceprivate UserService userService;@Resourceprivate ReplyService replyService;@Resourceprivate 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 {@Resourceprivate 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;}}

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。