package com.bw.controller;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.bw.pojo.Ids;
import com.bw.pojo.Product;
import com.bw.pojo.ShoppingCar;
import com.bw.pojo.User;
import com.bw.service.ProductService;
import com.bw.service.ShoppingCarService;
@Controller
@RequestMapping("shop")
public class ShoppingCarController {
@Autowired
private ShoppingCarService ss;
@Autowired
private ProductService ps;
@RequestMapping("addShoppingCar")
public String addShoppingCar(Integer id, HttpSession session,
ShoppingCar shoppingCar) {
ShoppingCar selectById = ss.selectById(id);
if (selectById == null) {
Product product = ps.selectById(id);
User user = (User) session.getAttribute("user");
shoppingCar.setProduct(product);
shoppingCar.setUser(user);
shoppingCar.setCount(1);
shoppingCar.setPriceCount(product.getPrice());
ss.insertShoppingCar(shoppingCar);
} else {
selectById.setCount(selectById.getCount() + 1);
ss.updateShoppingCar(selectById);
}
return null;
}
/*
@RequestMapping("addOrder")
public String addOrder(Integer id, HttpSession session,
ShoppingCar shoppingCar) {
Product product = ps.selectById(id);
User user = (User) session.getAttribute("user");
shoppingCar.setProduct(product);
shoppingCar.setUser(user);
shoppingCar.setCount(1);
shoppingCar.setPriceCount(product.getPrice());
Integer integer = ss.insertShoppingCar(shoppingCar);
System.out.println(integer);
return null;
}*/
@RequestMapping("selectShop")
@ResponseBody
public List<ShoppingCar> selectShop(HttpSession session) {
User user = (User) session.getAttribute("user");
List<ShoppingCar> list = ss.selectShop(user);
return list;
}
@RequestMapping("deleteShop")
public String deleteShop(Ids ids, HttpSession session) {
User user = (User) session.getAttribute("user");
ids.setUid(user.getId());
ss.deleteShop(ids);
return "";
}
@RequestMapping("reduceShop")
public String updateShoppingCar(ShoppingCar sc, HttpSession session) {
User user = (User) session.getAttribute("user");
ShoppingCar selectById = ss.selectById(sc.getProduct().getId());
Integer count = selectById.getCount();
Integer newcount = --count;
sc.setUser(user);
sc.setCount(newcount);
sc.setPriceCount(newcount*sc.getProduct().getPrice());
ss.updateShop(sc);
return "";
}
@RequestMapping("addShop")
public String addShoppingCar(ShoppingCar sc, HttpSession session) {
User user = (User) session.getAttribute("user");
ShoppingCar selectById = ss.selectById(sc.getProduct().getId());
Integer count = selectById.getCount();
Integer newcount = ++count;
sc.setUser(user);
sc.setCount(newcount);
sc.setPriceCount(newcount*sc.getProduct().getPrice());
ss.updateShop(sc);
return "";
}
@RequestMapping("buycheShop")
public String buycheShop(String ids) {
String[] split = ids.split(",");
for (String string : split) {
String trim = string.trim();
ss.insertOeder(Integer.parseInt(trim));
}
return "shop";
}
}
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.bw.pojo.Ids;
import com.bw.pojo.Product;
import com.bw.pojo.ShoppingCar;
import com.bw.pojo.User;
import com.bw.service.ProductService;
import com.bw.service.ShoppingCarService;
@Controller
@RequestMapping("shop")
public class ShoppingCarController {
@Autowired
private ShoppingCarService ss;
@Autowired
private ProductService ps;
@RequestMapping("addShoppingCar")
public String addShoppingCar(Integer id, HttpSession session,
ShoppingCar shoppingCar) {
ShoppingCar selectById = ss.selectById(id);
if (selectById == null) {
Product product = ps.selectById(id);
User user = (User) session.getAttribute("user");
shoppingCar.setProduct(product);
shoppingCar.setUser(user);
shoppingCar.setCount(1);
shoppingCar.setPriceCount(product.getPrice());
ss.insertShoppingCar(shoppingCar);
} else {
selectById.setCount(selectById.getCount() + 1);
ss.updateShoppingCar(selectById);
}
return null;
}
/*
@RequestMapping("addOrder")
public String addOrder(Integer id, HttpSession session,
ShoppingCar shoppingCar) {
Product product = ps.selectById(id);
User user = (User) session.getAttribute("user");
shoppingCar.setProduct(product);
shoppingCar.setUser(user);
shoppingCar.setCount(1);
shoppingCar.setPriceCount(product.getPrice());
Integer integer = ss.insertShoppingCar(shoppingCar);
System.out.println(integer);
return null;
}*/
@RequestMapping("selectShop")
@ResponseBody
public List<ShoppingCar> selectShop(HttpSession session) {
User user = (User) session.getAttribute("user");
List<ShoppingCar> list = ss.selectShop(user);
return list;
}
@RequestMapping("deleteShop")
public String deleteShop(Ids ids, HttpSession session) {
User user = (User) session.getAttribute("user");
ids.setUid(user.getId());
ss.deleteShop(ids);
return "";
}
@RequestMapping("reduceShop")
public String updateShoppingCar(ShoppingCar sc, HttpSession session) {
User user = (User) session.getAttribute("user");
ShoppingCar selectById = ss.selectById(sc.getProduct().getId());
Integer count = selectById.getCount();
Integer newcount = --count;
sc.setUser(user);
sc.setCount(newcount);
sc.setPriceCount(newcount*sc.getProduct().getPrice());
ss.updateShop(sc);
return "";
}
@RequestMapping("addShop")
public String addShoppingCar(ShoppingCar sc, HttpSession session) {
User user = (User) session.getAttribute("user");
ShoppingCar selectById = ss.selectById(sc.getProduct().getId());
Integer count = selectById.getCount();
Integer newcount = ++count;
sc.setUser(user);
sc.setCount(newcount);
sc.setPriceCount(newcount*sc.getProduct().getPrice());
ss.updateShop(sc);
return "";
}
@RequestMapping("buycheShop")
public String buycheShop(String ids) {
String[] split = ids.split(",");
for (String string : split) {
String trim = string.trim();
ss.insertOeder(Integer.parseInt(trim));
}
return "shop";
}
}