基于javaweb+mysql的springboot+mybatis在线水果商城系统(springboot+spring+springmvc+mybatis+html+mysql+redis)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot+MyBatis在线水果商城系统(springboot+spring+springmvc+mybatis+html+mysql+redis)
一、项目简述
功能: 区分为管理员用户和普通用户,普通用户:用户注册登录,首页水果展示,商品分类展示,购物车添加,下单,订单查询,个人信息修改,管理员用户:包括水果基本信息维护增删改查,分类管理,订单管理,用户管理等等功能。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
springboot+spring+springmvc+mybatis+html+mysql+redis+thymeleaf
// /**//* 进行发货//*/// @RequestMapping("/orderEnsure")// @ResponseBody// public Map<String, Object> orderEnsure(String id,String reserved1,HttpServletRequest request){// Map<String, Object> map = new HashMap<String, Object>();// HttpSession session = request.getSession();// int result = orderService.orderEnsure(id);// if (result == 1){// map.put("status", 0);// map.put("message", "发货成功");// }else {// map.put("status", 1);// map.put("message", "发货失败");// }// return map;// }}/*** 通用控制层*/@Controllerpublic class CommonController {@Resource(name = "orderService")OrderService orderService;@Resource(name = "userService")UserService userService;
map.put("search",search);List<Goods> lists = goodsService.findByPageSearchDr(map);Map<String, Object> map1 = new HashMap<String, Object>();map1.put("typeDr",typeDr);map1.put("search",search);// List<Goods> list = goodsService.selectSearchCountDr(map1);int count = goodsService.selectSearchCountDr(map1);if (count <= 0) {resultMap.put("status", 1);resultMap.put("message", "没有数据");resultMap.put("result", null);} else {int totalCount = count;double tc = totalCount;int totalPage = (int) Math.ceil(tc / pageSize);pageBean.setCurrentage(currentPage);pageBean.setPageSize(pageSize);pageBean.setTotalCount(totalCount);pageBean.setTotalPage(totalPage);pageBean.setLists(lists);resultMap.put("status", 0);resultMap.put("message", "有数据");resultMap.put("result", pageBean);}}return resultMap;}/*** 商品上架*/@RequestMapping("/goodsUp")@ResponseBodypublic Map<String, Object> goodsUp(String id) {Map<String, Object> map = new HashMap<String, Object>();int result = goodsService.goodsUp(id);if (result == 1) {map.put("status", 0);map.put("message", "上架成功");} else {map.put("status", 1);map.put("message", "上架失败");}
HttpSession session = request.getSession();String checkcode_server = (String) session.getAttribute("CHECKCODE");session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次User u = userService.findUserByUsername(username);if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 0) {User user = new User(username, password);int result = userService.updatePassword(user);if (result == 1) {map.put("status", 0);map.put("message", "修改成功");} else {map.put("status", 1);map.put("message", "修改失败,请检查信息是否正确");}} else {map.put("status", 1);map.put("message", "修改失败,请检查信息是否正确");}return map;}/*** 用户退出*/@RequestMapping("/userQuit")public String userQuit(HttpServletRequest request){HttpSession session = request.getSession();String auname = (String) session.getAttribute("adminUsername");if (auname == null){session.invalidate();App.goodscarList = null;App.ADDRESS = null;HttpSession session1 = request.getSession();session1.setAttribute("saveUsername", App.USERNAME);}else {session.removeAttribute("username");session.removeAttribute("saveUsername");session.removeAttribute("email");session.removeAttribute("goodsBrowse");session.removeAttribute("goodscarList");session.removeAttribute("count");session.removeAttribute("goodscarCount");session.removeAttribute("orders");session.removeAttribute("ordersEndListById");App.goodscarList = null;App.ADDRESS = null;session.setAttribute("saveUsername", App.USERNAME);}return "redirect:toIndex";}
try {//获取文件名String pname = file.getOriginalFilename();//获取文件格式String type = pname.substring(pname.lastIndexOf("."));//重命名String photo_name = App.getUid() + type;//将图片存到指定的位置//windows系统配置图片路径file.transferTo(new File(GoodsPhotoPath, photo_name));//mac系统配置图片路径//file.transferTo(new File("/Users/hanmeng/Desktop/java源码/Springboot生鲜水果商城/源码/GoodsPhoto", photo_name));//将图片信息存入商品对象goods.setPhoto(photo_name);//商品idgoods.setId(App.getUid());//商品状态goods.setDr(1);int i = goodsService.addGoods(goods);if (i == 1) {map.put("status", 0);map.put("message", "添加成功");} else {map.put("status", 1);map.put("message", "添加失败");}} catch (IOException e) {e.printStackTrace();}return map;}/*** 分页查询上架或下架商品列表信息*/@RequestMapping("/goodsTypeList")@ResponseBodypublic Map<String, Object> goodsTypeList(int currentPage, String search, int typeDr) {Map<String, Object> resultMap = new HashMap<String, Object>();PageBean<Goods> pageBean = new PageBean<Goods>();int pageSize = 5;int start = (currentPage - 1) * pageSize;int size = pageSize;if (search == "" || search == null) {Map<String, Object> map = new HashMap<String, Object>();map.put("start",start);map.put("size",size);map.put("typeDr",typeDr);List<Goods> lists = goodsService.findByPageDr(map);// List<Goods> list = goodsService.selectCountDr(typeDr);int count = goodsService.selectCountDr(typeDr);if (count <= 0) {
if (result == 1) {map.put("status", 0);map.put("message", "编辑成功");} else {map.put("status", 1);map.put("message", "编辑失败");}return map;}/*** 商品主页加载*/@RequestMapping("/indexList")@ResponseBodypublic Map<String, Object> indexList() {Map<String, Object> map = new HashMap<String, Object>();List<Goods> goodslist = goodsService.indexList();if (goodslist.size() <= 0) {map.put("status", 1);map.put("message", "暂无上架商品");map.put("result", null);} else {map.put("status", 0);map.put("message", "正在加载,请稍后");map.put("result", goodslist);}return map;}/*** 查看更多*/// @RequestMapping("/readMore")// public String readMore(String groupid, Model model) {// List<Goods> goodslist = goodsService.readMore(groupid);// if (goodslist.size() <= 0) {// return "redirect:toIndex";// } else {// List<Goods> goodsPart = new ArrayList<Goods>();// if (goodslist.size()>=2){//goodsPart.add(goodslist.get(goodslist.size() - 2));//goodsPart.add(goodslist.get(goodslist.size() - 1));// }else if((goodslist.size()==1)){//goodsPart.add(goodslist.get(goodslist.size() - 1));// }// model.addAttribute("groupid", groupid);// model.addAttribute("goodsPart", goodsPart);// model.addAttribute("goodslist", goodslist);// }
if (ordersWaitList.size()<=0){session.setAttribute("ordersWaitList",ordersWaitList);map.put("status", 1);map.put("message", "暂无订单");}else {session.setAttribute("ordersWaitList",ordersWaitList);map.put("status", 0);map.put("message", "订单查询成功");}return map;}/*** 已发货的订单*/@RequestMapping("/ordersEndList")@ResponseBodypublic Map<String, Object> ordersEndList(HttpServletRequest request){Map<String, Object> map = new HashMap<String, Object>();HttpSession session = request.getSession();List<Ordergoods> ordersEndList = orderService.ordersEndList();if (ordersEndList.size()<=0){map.put("status", 1);map.put("message", "暂无订单");}else {session.setAttribute("ordersEndList",ordersEndList);map.put("status", 0);map.put("message", "订单查询成功");}return map;}// /**//* 进行发货//*/// @RequestMapping("/orderEnsure")// @ResponseBody// public Map<String, Object> orderEnsure(String id,String reserved1,HttpServletRequest request){// Map<String, Object> map = new HashMap<String, Object>();// HttpSession session = request.getSession();// int result = orderService.orderEnsure(id);// if (result == 1){// map.put("status", 0);// map.put("message", "发货成功");// }else {// map.put("status", 1);// map.put("message", "发货失败");// }
Map<String, Object> map = new HashMap<String, Object>();map.put("start",start);map.put("size",size);map.put("search",search);List<Goods> lists = goodsService.findByPageSearch(map);// List<Goods> list = goodsService.selectSearchCount(search1);int count = goodsService.selectSearchCount(search);if (count <= 0) {resultMap.put("status", 1);resultMap.put("message", "没有数据");resultMap.put("result", null);} else {int totalCount = count;double tc = totalCount;int totalPage = (int) Math.ceil(tc / pageSize);pageBean.setCurrentage(currentPage);pageBean.setPageSize(pageSize);pageBean.setTotalCount(totalCount);pageBean.setTotalPage(totalPage);pageBean.setLists(lists);resultMap.put("status", 0);resultMap.put("message", "有数据");resultMap.put("result", pageBean);}}return resultMap;}/*** 添加商品*/@RequestMapping("/addGoods")@ResponseBodypublic Map<String, Object> addGoods(MultipartFile file, Goods goods) {Map<String, Object> map = new HashMap<String, Object>();try {//获取文件名String pname = file.getOriginalFilename();//获取文件格式String type = pname.substring(pname.lastIndexOf("."));//重命名String photo_name = App.getUid() + type;//将图片存到指定的位置
/*** 通用控制层*/@Controllerpublic class CommonController {@Resource(name = "orderService")OrderService orderService;@Resource(name = "userService")UserService userService;//用户登录@RequestMapping("/toUserLogin")public String userLogin(HttpServletRequest request) {HttpSession session = request.getSession();session.setAttribute("saveUsername", App.USERNAME);return "login";}//用户注册@RequestMapping("/toUserRegister")public String userRegister() {return "register";}//用户修改密码@RequestMapping("/userToForgetPwd")public String toForgetPwd(){return "fogetPwd";}//管理员登录@RequestMapping("/toAdminLogin")public String adminLogin(HttpServletRequest request) {
}return resultMap;}/*** 添加商品*/@RequestMapping("/addGoods")@ResponseBodypublic Map<String, Object> addGoods(MultipartFile file, Goods goods) {Map<String, Object> map = new HashMap<String, Object>();try {//获取文件名String pname = file.getOriginalFilename();//获取文件格式String type = pname.substring(pname.lastIndexOf("."));//重命名String photo_name = App.getUid() + type;//将图片存到指定的位置//windows系统配置图片路径file.transferTo(new File(GoodsPhotoPath, photo_name));//mac系统配置图片路径//file.transferTo(new File("/Users/hanmeng/Desktop/java源码/Springboot生鲜水果商城/源码/GoodsPhoto", photo_name));//将图片信息存入商品对象goods.setPhoto(photo_name);//商品idgoods.setId(App.getUid());//商品状态goods.setDr(1);int i = goodsService.addGoods(goods);if (i == 1) {map.put("status", 0);map.put("message", "添加成功");} else {map.put("status", 1);map.put("message", "添加失败");}} catch (IOException e) {e.printStackTrace();}return map;}/*** 分页查询上架或下架商品列表信息*/@RequestMapping("/goodsTypeList")@ResponseBodypublic Map<String, Object> goodsTypeList(int currentPage, String search, int typeDr) {Map<String, Object> resultMap = new HashMap<String, Object>();PageBean<Goods> pageBean = new PageBean<Goods>();int pageSize = 5;int start = (currentPage - 1) * pageSize;
}/*** 商品批量删除*/@RequestMapping("/deleteAll")@ResponseBodypublic Map<String, Object> deleteAll(String ids) {Map<String, Object> map = new HashMap<String, Object>();String[] id_s = ids.split(",");int result = goodsService.deleteAll(id_s);if (result >= 1) {map.put("status", 0);map.put("message", "删除成功");} else {map.put("status", 1);map.put("message", "删除失败");}return map;}/*** 管理员查看商品详情*/@RequestMapping("/goodsDetail")@ResponseBodypublic Map<String, Object> goodsDetail(String photo) {Map<String, Object> map = new HashMap<String, Object>();Goods goods = goodsService.goodsDetail(photo);if (goods != null) {map.put("status", 0);map.put("message", "加载成功");map.put("result", goods);} else {map.put("status", 1);map.put("message", "加载失败");map.put("result", null);}return map;}/*** 加载商品信息
}/*** 已发货的订单*/@RequestMapping("/ordersEndList")@ResponseBodypublic Map<String, Object> ordersEndList(HttpServletRequest request){Map<String, Object> map = new HashMap<String, Object>();HttpSession session = request.getSession();List<Ordergoods> ordersEndList = orderService.ordersEndList();if (ordersEndList.size()<=0){map.put("status", 1);map.put("message", "暂无订单");}else {session.setAttribute("ordersEndList",ordersEndList);map.put("status", 0);map.put("message", "订单查询成功");}return map;}// /**//* 进行发货//*/// @RequestMapping("/orderEnsure")// @ResponseBody// public Map<String, Object> orderEnsure(String id,String reserved1,HttpServletRequest request){// Map<String, Object> map = new HashMap<String, Object>();// HttpSession session = request.getSession();// int result = orderService.orderEnsure(id);// if (result == 1){// map.put("status", 0);// map.put("message", "发货成功");// }else {// map.put("status", 1);// map.put("message", "发货失败");// }// return map;// }}
/*** 加载商品信息*/@RequestMapping("/loadGoods")@ResponseBodypublic Map<String, Object> loadGoods(String id) {Map<String, Object> map = new HashMap<String, Object>();Goods goods = goodsService.loadGoods(id);if (goods != null) {map.put("status", 0);map.put("message", "加载编辑成功");map.put("result", goods);} else {map.put("status", 1);map.put("message", "加载编辑失败");map.put("result", null);}return map;}/*** 商品编辑*/@RequestMapping("/goodsUpdate")@ResponseBodypublic Map<String, Object> goodsUpdate(String id, String price, String count) {Map<String, Object> map = new HashMap<String, Object>();double price_double = Double.parseDouble(price);double count_double = Double.parseDouble(count);Map<String, Object> map1 = new HashMap<String, Object>();map1.put("id",id);map1.put("price",price_double);map1.put("count",count_double);int result = goodsService.goodsUpdate(map1);if (result == 1) {map.put("status", 0);map.put("message", "编辑成功");} else {map.put("status", 1);map.put("message", "编辑失败");}return map;}/*** 商品主页加载*/@RequestMapping("/indexList")@ResponseBodypublic Map<String, Object> indexList() {Map<String, Object> map = new HashMap<String, Object>();List<Goods> goodslist = goodsService.indexList();
@ResponseBodypublic Map<String, Object> adminForgetPwd(String username, String password, String email, String checkcode, HttpServletRequest request) {Map<String, Object> map = new HashMap<String, Object>();HttpSession session = request.getSession();String checkcode_server = (String) session.getAttribute("CHECKCODE");session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次User u = userService.findUserByUsername(username);if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 1) {User user = new User(username, password);int result = userService.updatePassword(user);if (result == 1) {map.put("status", 0);map.put("message", "修改成功");} else {map.put("status", 1);map.put("message", "修改失败,请检查信息是否正确");}} else {map.put("status", 1);map.put("message", "修改失败,请检查信息是否正确");}return map;}/*** 用户修改密码*/@RequestMapping("/userForgetPwd")@ResponseBodypublic Map<String, Object> forgetPwd(String username, String password, String email, String checkcode, HttpServletRequest request) {Map<String, Object> map = new HashMap<String, Object>();HttpSession session = request.getSession();String checkcode_server = (String) session.getAttribute("CHECKCODE");session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次User u = userService.findUserByUsername(username);if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 0) {User user = new User(username, password);int result = userService.updatePassword(user);if (result == 1) {map.put("status", 0);map.put("message", "修改成功");} else {map.put("status", 1);map.put("message", "修改失败,请检查信息是否正确");
Map<String, Object> map = new HashMap<String, Object>();User u = userService.findUserByUsername(username);if (u == null || u.getDr() == 0) {map.put("status", 1);map.put("message", "登录失败,请检查信息是否正确");} else {if (u.getPassword().equals(password)) {session.setAttribute("adminUsername", username);session.setAttribute("adminEmail", u.getEmail());if (checked == 1) {App.ADMIN_USERNAME = username;App.ADMIN_PASSWORD = password;} else if (checked == 0) {App.ADMIN_USERNAME = null;App.ADMIN_PASSWORD = null;}map.put("status", 0);map.put("message", "登录成功");} else {map.put("status", 1);map.put("message", "登录失败,请检查信息是否正确");}}return map;}/*** 管理员修改密码*/@RequestMapping("/userAdminForgetPwd")@ResponseBodypublic Map<String, Object> adminForgetPwd(String username, String password, String email, String checkcode, HttpServletRequest request) {Map<String, Object> map = new HashMap<String, Object>();HttpSession session = request.getSession();String checkcode_server = (String) session.getAttribute("CHECKCODE");session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次User u = userService.findUserByUsername(username);if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 1) {User user = new User(username, password);int result = userService.updatePassword(user);if (result == 1) {map.put("status", 0);map.put("message", "修改成功");} else {map.put("status", 1);map.put("message", "修改失败,请检查信息是否正确");
Map<String, Object> map = new HashMap<String, Object>();User u = userService.findUserByUsername(username);if (u == null || u.getDr() == 0) {map.put("status", 1);map.put("message", "登录失败,请检查信息是否正确");} else {if (u.getPassword().equals(password)) {session.setAttribute("adminUsername", username);session.setAttribute("adminEmail", u.getEmail());if (checked == 1) {App.ADMIN_USERNAME = username;App.ADMIN_PASSWORD = password;} else if (checked == 0) {App.ADMIN_USERNAME = null;App.ADMIN_PASSWORD = null;}map.put("status", 0);map.put("message", "登录成功");} else {map.put("status", 1);map.put("message", "登录失败,请检查信息是否正确");}}return map;}/*** 管理员修改密码*/@RequestMapping("/userAdminForgetPwd")@ResponseBodypublic Map<String, Object> adminForgetPwd(String username, String password, String email, String checkcode, HttpServletRequest request) {Map<String, Object> map = new HashMap<String, Object>();HttpSession session = request.getSession();String checkcode_server = (String) session.getAttribute("CHECKCODE");session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次User u = userService.findUserByUsername(username);if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 1) {User user = new User(username, password);int result = userService.updatePassword(user);if (result == 1) {map.put("status", 0);map.put("message", "修改成功");
if (goodslist.size()>=2){goodsNews.add(goodslist.get(goodslist.size() - 2));goodsNews.add(goodslist.get(goodslist.size() - 1));}else if(goodslist.size()==1){goodsNews.add(goodslist.get(goodslist.size() - 1));}model.addAttribute("goodsNews", goodsNews);model.addAttribute("goods", goods);}return "shop_message";}/*** 商品主页搜索*/@RequestMapping("/goodsSearch")public String goodsSearch(String search, Model model) {if (search == "" || search == null) {return "redirect:toNoPage";}List<Goods> goodslist = goodsService.goodsSearch(search);if (goodslist.size() <= 0) {return "redirect:toNoPage";} else {model.addAttribute("goodslist", goodslist);}return "searchmoreShop";}}
} else {map.put("status", 1);map.put("message", "删除失败");}return map;}/*** 管理员查看商品详情*/@RequestMapping("/goodsDetail")@ResponseBodypublic Map<String, Object> goodsDetail(String photo) {Map<String, Object> map = new HashMap<String, Object>();Goods goods = goodsService.goodsDetail(photo);if (goods != null) {map.put("status", 0);map.put("message", "加载成功");map.put("result", goods);} else {map.put("status", 1);map.put("message", "加载失败");map.put("result", null);}return map;}/*** 加载商品信息*/@RequestMapping("/loadGoods")@ResponseBodypublic Map<String, Object> loadGoods(String id) {Map<String, Object> map = new HashMap<String, Object>();Goods goods = goodsService.loadGoods(id);if (goods != null) {map.put("status", 0);map.put("message", "加载编辑成功");map.put("result", goods);} else {map.put("status", 1);map.put("message", "加载编辑失败");map.put("result", null);}return map;}/*** 商品编辑*/@RequestMapping("/goodsUpdate")@ResponseBodypublic Map<String, Object> goodsUpdate(String id, String price, String count) {Map<String, Object> map = new HashMap<String, Object>();