项目编号:BS-SC-031
一,项目简介
本项目开发实现基于SSM框来进行,完成了一个主要用于销售用果和蔬菜等产品的在线商城销售管理系统。系统的前端用户可以实现注册登陆、在线浏览商品、在线添加购物车、在线购买、全文搜索、查看购物车、在线收藏、查看个人订单、修改个人信息等。后台管理用户可以管理商品分类、商品信息、订单信息、用户信息、留言信息、公告信息等相关数据。业务功能完整,页面简洁大方。
二,环境介绍
语言环境:Java: jdk1.8
数据库:Mysql: mysql5.7
应用服务器:Tomcat: tomcat8.5.31
开发工具:IDEA或eclipse
三,系统展示
首页
商品浏览
添加购物车
个人中心
商品收藏
添加购物车
个人中心
商品收藏
我的订单
后台管理
类目管理
用户管理
商品管理
订单管理
公告管理
留言管理
四,核心代码展示
package com.javapandeng.controller; import com.alibaba.fastjson.JSONObject; import com.javapandeng.po.Car; import com.javapandeng.po.Item; import com.javapandeng.service.CarService; import com.javapandeng.service.ItemService; import com.javapandeng.utils.Consts; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; /** * 购物车 */ @Controller @RequestMapping("/car") public class CarController { @Autowired private CarService carService; @Autowired private ItemService itemService; @RequestMapping("/exAdd") @ResponseBody public String exAdd(Car car, HttpServletRequest request){ JSONObject js = new JSONObject(); Object attribute = request.getSession().getAttribute(Consts.ID); if(attribute==null){ js.put(Consts.RES,0); return js.toJSONString(); } //保存到购物车 Integer userId = Integer.valueOf(attribute.toString()); car.setUserId(userId); Item item = itemService.load(car.getItemId()); String price = item.getPrice(); Double valueOf = Double.valueOf(price); car.setPrice(valueOf); if(item.getZk()!=null){ valueOf = valueOf*item.getZk()/10; BigDecimal bg = new BigDecimal(valueOf).setScale(2, RoundingMode.UP); car.setPrice(bg.doubleValue()); valueOf = bg.doubleValue(); } Integer num = car.getNum(); Double t = valueOf*num; BigDecimal bg = new BigDecimal(t).setScale(2, RoundingMode.UP); double doubleValue = bg.doubleValue(); car.setTotal(doubleValue+""); carService.insert(car); js.put(Consts.RES,1); return js.toJSONString(); } /** * 转向我的购物车页面 */ @RequestMapping("/findBySql") public String findBySql(Model model, HttpServletRequest request){ Object attribute = request.getSession().getAttribute(Consts.ID); if(attribute==null){ return "redirect:/login/toLogin"; } Integer userId = Integer.valueOf(attribute.toString()); String sql = "select * from car where user_id="+userId+" order by id desc"; List<Car> list = carService.listBySqlReturnEntity(sql); model.addAttribute("list",list); return "car/car"; } /** * 删除购物车 */ @RequestMapping("/delete") @ResponseBody public String delete(Integer id){ carService.deleteById(id); return "success"; } }
package com.javapandeng.controller; import com.javapandeng.base.BaseController; import com.javapandeng.po.Comment; import com.javapandeng.service.CommentService; import com.javapandeng.utils.Consts; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; import java.util.Date; /** * 评论 */ @Controller @RequestMapping("/comment") public class CommentController extends BaseController { @Autowired private CommentService commentService; /** * 添加执行 */ @RequestMapping("/exAdd") public String exAdd(Comment comment, HttpServletRequest request){ Object attribute = request.getSession().getAttribute(Consts.ID); if(attribute==null){ return "redirect:/login/toLogin"; } Integer userId = Integer.valueOf(attribute.toString()); comment.setAddTime(new Date()); comment.setUserId(userId); commentService.insert(comment); return "redirect:/itemOrder/myOrder.action"; } }
package com.javapandeng.controller; import com.javapandeng.base.BaseController; import com.javapandeng.po.User; import com.javapandeng.service.UserService; import com.javapandeng.utils.Consts; import com.javapandeng.utils.Pager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import javax.persistence.criteria.CriteriaBuilder; import javax.servlet.http.HttpServletRequest; @Controller @RequestMapping("/user") public class UserController extends BaseController { @Autowired private UserService userService; /** * 分页查询用户 * @param model * @param user * @return */ @RequestMapping("findBySql") public String findBySql(Model model, User user){ String sql="select * from user where 1=1 "; if(!isEmpty(user.getUserName())){ sql+=" and userName like '%"+user.getUserName()+"%' "; } sql+=" order by id"; Pager<User> pagers= userService.findBySqlRerturnEntity(sql); model.addAttribute("pagers",pagers); model.addAttribute("obj", user); return "user/user"; } /** * 删除用户 * @return */ @RequestMapping("delete") public String delete(Integer id){ userService.deleteById(id); return "redirect:/user/findBySql.action"; } /** * 跳到个人中心页面,产看用户信息 * @return */ @RequestMapping("view") public String view(Model model, HttpServletRequest request){ Object session =request.getSession().getAttribute(Consts.ID); if(session==null){ return "redirect:/login/uLogin.action"; } Integer userId=Integer.valueOf(session.toString()); User byId = userService.getById(userId); model.addAttribute("obj",byId); return "user/view"; } /** * 跳到个人中心页面,产看用户信息 * @return */ @RequestMapping("exUpdate") public String exUpdate(User user,HttpServletRequest request){ Object session =request.getSession().getAttribute(Consts.ID); if(session==null){ return "redirect:/login/uLogin.action"; } user.setId(Integer.valueOf(session.toString())); userService.updateById(user); return "redirect:/user/view.action"; } }
package com.javapandeng.controller; import com.alibaba.fastjson.JSONObject; import com.javapandeng.base.BaseController; import com.javapandeng.po.*; import com.javapandeng.service.*; import com.javapandeng.utils.Consts; import com.javapandeng.utils.Pager; import jdk.nashorn.internal.ir.RuntimeNode; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @Controller @RequestMapping("/itemOrder") public class ItemOrderController extends BaseController { @Autowired private ItemOrderService itemOrderService; @Autowired private UserService userService; @Autowired private CarService carService; @Autowired private OrderDetailService orderDetailService; @Autowired private ItemService itemService; /* 管理员界面查看所有订单 */ @RequestMapping("findBySql") public String findBySql (ItemOrder itemOrder, Model model){ String sql="select * from item_order where 1=1"; if(!isEmpty(itemOrder.getCode())){ sql+=" and code like '%"+itemOrder.getCode()+"%'" ; } sql+=" order by id desc"; Pager<ItemOrder> pagers= itemOrderService.findBySqlRerturnEntity(sql); model.addAttribute("pagers",pagers); model.addAttribute("obj", itemOrder); return "itemOrder/itemOrder"; } /* 用户个人界面查看所有订单 */ @RequestMapping("myOrder") public String myOrder (HttpServletRequest request, Model model){ Object attribute = request.getSession().getAttribute(Consts.ID); if(attribute==null){ return "redirect:/login/uLogin"; } Integer userId= Integer.valueOf(attribute.toString()); //全部订单 String sql = "select * from item_order where user_id="+userId+" order by id desc"; List<ItemOrder> all = itemOrderService.listBySqlReturnEntity(sql); //待发货 String sql2 = "select * from item_order where user_id="+userId+" and status=0 order by id desc"; List<ItemOrder> dfh = itemOrderService.listBySqlReturnEntity(sql2); //已取消 String sql3 = "select * from item_order where user_id="+userId+" and status=1 order by id desc"; List<ItemOrder> yqx = itemOrderService.listBySqlReturnEntity(sql3); //已发货 String sql4 = "select * from item_order where user_id="+userId+" and status=2 order by id desc"; List<ItemOrder> dsh = itemOrderService.listBySqlReturnEntity(sql4); //已收货 String sql5 = "select * from item_order where user_id="+userId+" and status=3 order by id desc"; List<ItemOrder> ysh = itemOrderService.listBySqlReturnEntity(sql5); model.addAttribute("all",all); model.addAttribute("dfh",dfh); model.addAttribute("yqx",yqx); model.addAttribute("dsh",dsh); model.addAttribute("ysh",ysh); return "itemOrder/myOrder"; } /** * 购物车结算提交 */ @RequestMapping("/exAdd") @ResponseBody public String exAdd(@RequestBody List<CarDto> list, HttpServletRequest request){ Object attribute = request.getSession().getAttribute(Consts.ID); JSONObject js = new JSONObject(); if(attribute==null){ js.put(Consts.RES,0);//res=0,在前端页面ajax里提示需要登录 return js.toJSONString(); } Integer userId = Integer.valueOf(attribute.toString()); User byId = userService.getById(userId); if(StringUtils.isEmpty(byId.getAddress())){ js.put(Consts.RES,2);//res=2,在前端页面ajax里提示需要地址 return js.toJSONString(); } List<Integer> ids = new ArrayList<>(); BigDecimal to = new BigDecimal(0); for(CarDto c:list){ ids.add(c.getId()); Car load = carService.load(c.getId()); to = to.add(new BigDecimal(load.getPrice()).multiply(new BigDecimal(c.getNum()))); } ItemOrder order = new ItemOrder(); order.setStatus(0); order.setCode(getOrderNo()); order.setIsDelete(0); order.setTotal(to.setScale(2,BigDecimal.ROUND_HALF_UP).toString()); order.setUserId(userId); order.setAddTime(new Date()); itemOrderService.insert(order); //订单详情放入orderDetail,删除购物车 if(!CollectionUtils.isEmpty(ids)){ for(CarDto c:list){ Car load = carService.load(c.getId()); OrderDetail de = new OrderDetail(); de.setItemId(load.getItemId()); de.setOrderId(order.getId()); de.setStatus(0); de.setNum(c.getNum()); de.setTotal(String.valueOf(c.getNum()*load.getPrice())); orderDetailService.insert(de); //修改成交数 Item load2 = itemService.load(load.getItemId()); load2.setGmNum(load2.getGmNum()+c.getNum()); itemService.updateById(load2); //删除购物车 carService.deleteById(c.getId()); } } js.put(Consts.RES,1); return js.toJSONString(); } private static String date; private static long orderNum = 0L; public static synchronized String getOrderNo(){ String str = new SimpleDateFormat("yyyyMMddHHmm").format(new Date()); if(date==null||!date.equals(str)){ date = str; orderNum = 0L; } orderNum++; long orderNO = Long.parseLong(date)*10000; orderNO += orderNum; return orderNO+""; } /** * 取消订单 */ @RequestMapping("/qx") public String qx(Integer id,Model model){ ItemOrder obj =itemOrderService.load(id); obj.setStatus(1); itemOrderService.updateById(obj); model.addAttribute("obj",obj); return "redirect:/itemOrder/myOrder"; } /** * 后台发货 */ @RequestMapping("/fh") public String fh(Integer id,Model model){ ItemOrder obj =itemOrderService.load(id); obj.setStatus(2); itemOrderService.updateById(obj); model.addAttribute("obj",obj); return "redirect:/itemOrder/findBySql"; } /** * 用户收货 */ @RequestMapping("/sh") public String sh(Integer id,Model model){ ItemOrder obj =itemOrderService.load(id); obj.setStatus(3); itemOrderService.updateById(obj); model.addAttribute("obj",obj); return "redirect:/itemOrder/myOrder"; } /** * 用户评价入口 */ @RequestMapping("/pj") public String pj(Integer id,Model model){ model.addAttribute("id",id); return "itemOrder/pj"; } }
package com.javapandeng.controller; import com.javapandeng.base.BaseController; import com.javapandeng.po.News; import com.javapandeng.service.NewsService; import com.javapandeng.utils.Pager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import java.util.Date; @Controller @RequestMapping("/news") public class NewsController extends BaseController { @Autowired NewsService newsService; @RequestMapping("findBySql") public String findBySql(News news, Model model){ String sql="select * from news where 1=1 "; if(!isEmpty(news.getName())){ sql+=" and name like '%"+news.getName()+"%'"; } sql+="order by id desc"; Pager<News> pagers= newsService.findBySqlRerturnEntity(sql); model.addAttribute("pagers",pagers); model.addAttribute("obj", news); return "news/news"; } /** *跳转到添加公告页面 */ @RequestMapping("add") public String add(){ return "news/add"; } /** *添加公告 */ @RequestMapping("exAdd") public String exAdd(News news){ news.setAddTime(new Date()); newsService.insert(news); return "redirect:/news/findBySql.antion"; } /** * 跳到修改公告页面 * @return */ @RequestMapping("update") public String update(Integer id,Model model){ News news=newsService.getById(id); System.out.println(news); model.addAttribute("obj",news); return "news/update"; } /** * 修改公告并保存 * @return */ @RequestMapping("exUpdate") public String exUpdate(News news){ newsService.updateById(news); return "redirect:/news/findBySql.action"; } /** * 删除公告 * @return */ @RequestMapping("delete") public String delete(Integer id){ newsService.deleteById(id); return "redirect:/news/findBySql.action"; } /** * 前端公告列表 */ @RequestMapping("/list") public String list(Model model){ Pager<News> pagers = newsService.findByEntity(new News()); model.addAttribute("pagers",pagers); return "news/list"; } /** * 公告详情页面 */ @RequestMapping("/view") public String view(Integer id,Model model){ News obj = newsService.load(id); model.addAttribute("obj",obj); return "news/view"; } }
五,项目总结
本项目开发实现基于SSM框来进行,完成了一个主要用于销售用果和蔬菜等产品的在线商城销售管理系统。系统的前端用户可以实现注册登陆、在线浏览商品、在线添加购物车、在线购买、全文搜索、查看购物车、在线收藏、查看个人订单、修改个人信息等。后台管理用户可以管理商品分类、商品信息、订单信息、用户信息、留言信息、公告信息等相关数据。业务功能完整,页面简洁大方。