首页 > 分享 > SSM实现网上商城 有聊天功能

SSM实现网上商城 有聊天功能

1.项目介绍

     实现一个网上商城,商品信息展示,购物车,订单管理,个人中心,商品评价,商品搜索,地址管理,聊天,后台管理(商品增删改查),分类管理,活动管理,客服聊天回复

2.开发环境

开发环境:IDEA/eclipse、Tomcat8.5+数据库:MySql前端主要使用Bootstrap以及JQuery,后端基于SpringMVC、Spring、MyBatis进行开发,使用Maven构建activeMQ

 

 

 

相关代码

@Controller

public class OrderController {

@Autowired

private AddressService addressService;

@Autowired

private ShopCartService shopCartService;

@Autowired

private GoodsService goodsService;

@Autowired

private OrderService orderService;

@Autowired

private ActivityService activityService;

@RequestMapping("/order")

public String showOrder(HttpSession session, Model model) {

User user = (User) session.getAttribute("user");

if (user == null) {

return "redirect:/login";

}

AddressExample addressExample = new AddressExample();

addressExample.or().andUseridEqualTo(user.getUserid());

List<Address> addressList = addressService.getAllAddressByExample(addressExample);

model.addAttribute("address", addressList);

ShopCartExample shopCartExample = new ShopCartExample();

shopCartExample.or().andUseridEqualTo(user.getUserid());

List<ShopCart> shopCart = shopCartService.selectByExample(shopCartExample);

List<Goods> goodsAndImage = new ArrayList<>();

Float totalPrice = new Float(0);

Integer oldTotalPrice = 0;

for (ShopCart cart:shopCart) {

Goods goods = goodsService.selectById(cart.getGoodsid());

List<ImagePath> imagePathList = goodsService.findImagePath(goods.getGoodsid());

goods.setImagePaths(imagePathList);

goods.setNum(cart.getGoodsnum());

Activity activity = activityService.selectByKey(goods.getActivityid());

goods.setActivity(activity);

if(activity.getDiscount() != 1) {

goods.setNewPrice(goods.getPrice()*goods.getNum()* activity.getDiscount());

} else if(activity.getFullnum() != null) {

if (goods.getNum() >= activity.getFullnum()) {

goods.setNewPrice((float) (goods.getPrice()*(goods.getNum()-activity.getReducenum())));

} else {

goods.setNewPrice((float) (goods.getPrice()*goods.getNum()));

}

} else {

goods.setNewPrice((float) (goods.getPrice()*goods.getNum()));

}

totalPrice = totalPrice + goods.getNewPrice();

oldTotalPrice = oldTotalPrice + goods.getNum() * goods.getPrice();

goodsAndImage.add(goods);

}

model.addAttribute("totalPrice", totalPrice);

model.addAttribute("oldTotalPrice", oldTotalPrice);

model.addAttribute("goodsAndImage", goodsAndImage);

return "orderConfirm";

}

@RequestMapping("/orderFinish")

@ResponseBody

public Msg orderFinish(Float oldPrice, Float newPrice, Boolean isPay, Integer addressid,HttpSession session) {

User user = (User) session.getAttribute("user");

ShopCartExample shopCartExample = new ShopCartExample();

shopCartExample.or().andUseridEqualTo(user.getUserid());

List<ShopCart> shopCart = shopCartService.selectByExample(shopCartExample);

for (ShopCart cart : shopCart) {

shopCartService.deleteByKey(new ShopCartKey(cart.getUserid(),cart.getGoodsid()));

}

Order order = new Order(null, user.getUserid(), new Date(), oldPrice, newPrice, isPay, false, false, false, addressid,null,null);

orderService.insertOrder(order);

Integer orderId = order.getOrderid();

for (ShopCart cart : shopCart) {

orderService.insertOrderItem(new OrderItem(null, orderId, cart.getGoodsid(), cart.getGoodsnum()));

}

return Msg.success("购买成功");

}

}

@Controller

public class MainController {

@Autowired

private CateService cateService;

@Autowired

private GoodsService goodsService;

@RequestMapping("/main")

public String showAllGoods(Model model, HttpSession session) {

Integer userid;

User user = (User) session.getAttribute("user");

if (user == null) {

userid = null;

} else {

userid = user.getUserid();

}

List<Goods> digGoods = getCateGoods("数码", userid);

model.addAttribute("digGoods", digGoods);

List<Goods> houseGoods = getCateGoods("家电", userid);

model.addAttribute("houseGoods", houseGoods);

List<Goods> colGoods = getCateGoods("服饰", userid);

model.addAttribute("colGoods", colGoods);

List<Goods> bookGoods = getCateGoods("书籍", userid);

model.addAttribute("bookGoods", bookGoods);

return "main";

}

public List<Goods> getCateGoods(String cate, Integer userid) {

CategoryExample digCategoryExample = new CategoryExample();

digCategoryExample.or().andCatenameLike(cate);

List<Category> digCategoryList = cateService.selectByExample(digCategoryExample);

if (digCategoryList.size() == 0) {

return null;

}

GoodsExample digGoodsExample = new GoodsExample();

List<Integer> digCateId = new ArrayList<Integer>();

for (Category tmp:digCategoryList) {

digCateId.add(tmp.getCateid());

}

digGoodsExample.or().andCategoryIn(digCateId);

List<Goods> goodsList = goodsService.selectByExampleLimit(digGoodsExample);

List<Goods> goodsAndImage = new ArrayList<>();

for (Goods goods:goodsList) {

if (userid == null) {

goods.setFav(false);

} else {

Favorite favorite = goodsService.selectFavByKey(new FavoriteKey(userid, goods.getGoodsid()));

if (favorite == null) {

goods.setFav(false);

} else {

goods.setFav(true);

}

}

List<ImagePath> imagePathList = goodsService.findImagePath(goods.getGoodsid());

goods.setImagePaths(imagePathList);

goodsAndImage.add(goods);

}

return goodsAndImage;

}

}

相关知识

基于SSM的植物园管理系统设计与实现
Java SSM 实现的网上花店系统设计
【开题报告】基于SSM的多肉植物种植分享平台的设计与实现
计算机优秀毕业设计论文参考。基于 SSM 的网上鲜花订购系统
(附源码)基于SSM鲜花商城设计与实现
基于SSM技术的鲜花销售管理系统设计与实现
基于SSM的鲜花线上销售系统设计与实现
SSM开心鲜花系统5o1dr 虚拟支付
基于java(ssm)线上花店管理系统设计与实现(源码+lw+部署文档+讲解等)
ssm基于Javaweb的网上花店系统的设计与实现论文

网址: SSM实现网上商城 有聊天功能 https://m.huajiangbk.com/newsview821303.html

所属分类:花卉
上一篇: 人参红颜茶 组合花茶花草茶配方茶
下一篇: 4款养颜美容花草茶的配方