ssm技术实现购物车
来源:互联网 发布:金思维网络 编辑:程序博客网 时间:2024/05/17 10:57
dao层 mapper
public interface ShoppingMapper {
//添加购物车void Shoppingadd(Shopping s);
//修改数据数量
void ShoppingUp(Shopping s);
//查詢是否相同
Shopping selectAll(Shopping s);
//显示购物车
List<Shopping> selectShow(Shopping s);
//
Shopping selectShowtwo(Shopping s);
//删除
void delete(int id);
}
<insert id="Shoppingadd" parameterType="shopping">
insert into z_shoppingcart(count,priceCount,p_id,u_id)
values(#{count},#{priceCount},#{p.pid},#{u.uid})
</insert>
<update id="ShoppingUp" parameterType="shopping">
update z_shoppingcart set count=#{count} where p_id=#{p.pid}
</update>
<resultMap type="shopping" id="rm">
<id column="id" property="id"/>
<result column="count" property="count"/>
<result column="priceCount" property="priceCount"/>
<association property="u" javaType="user">
<id column="uid" property="uid"/>
<result column="name" property="name"/>
<result column="pwd" property="pwd"/>
</association>
<association property="p" javaType="product">
<id column="pid" property="pid"/>
<result column="pname" property="pname"/>
<result column="price" property="price"/>
</association>
</resultMap>
<select id="selectAll" parameterType="shopping" resultMap="rm">
select * from z_shoppingcart s,z_product p,z_user u where s.p_id=p.pid
<if test="p!=null and p.pid!=0">
and s.p_id=#{p.pid}
</if>
<if test="id!=null and id!=0">
and id=#{id}
</if>
</select>
<select id="selectShow" parameterType="shopping" resultMap="rm">
select * from z_shoppingcart s,z_product p,z_user u where s.p_id=p.pid and s.u_id=u.uid
<if test="u!=null and u.uid!=0">
and s.u_id=#{u.uid}
</if>
<if test="p!=null and p.pid!=0">
and s.p_id=#{p.pid}
</if>
</select>
<delete id="delete" parameterType="int">
delete from z_shoppingcart where id=#{id}
</delete>
</mapper>
public interface ProductMapper {
List<Product> ProductShow();
List<Product> ProductName(String name);
Product selectShowtwo(int id);
}
<select id="ProductShow" resultType="product">
select * from z_product
</select>
<select id="ProductName" parameterType="string" resultType="product">
select * from z_product where pname like '%${value}%'
</select>
<select id="selectShowtwo" parameterType="int" resultType="product">
select * from z_product where pid=#{pid}
</select>
public interface OrderMapper {
void orderadd(Order o);
}
<insert id="orderadd" parameterType="order">
insert into z_order(shop_id,u_id)values(#{oid},#{u.uid})
</insert>
service层 实现类
public interface ShoppingService {
// 添加购物车
void Shoppingadd(Shopping s);
// 修改数据数量
void ShoppingUp(Shopping s);
//判断是否相同
void listall(Shopping s);
//
List<Shopping> selectShow(Shopping s);
//
Shopping selectAll(Shopping s);
//
Shopping selectShowtwo(Shopping s);
//
void delete(int id);
}
@Service
@Transactional
public class ShoppingServiceimpl implements ShoppingService{
@Autowired
private ShoppingMapper shop;
@Override
public void Shoppingadd(Shopping s) {
shop.Shoppingadd(s);
}
@Override
public void ShoppingUp(Shopping s) {
shop.ShoppingUp(s);
}
@Override
public void listall(Shopping s) {
Shopping selectAll = shop.selectAll(s);
if(selectAll==null){
s.setCount(1);
s.setPriceCount(s.getP().getPrice()*s.getCount());
Shoppingadd(s);
}else{
selectAll.setCount(selectAll.getCount()+1);
selectAll.setPriceCount(selectAll.getP().getPrice()*selectAll.getCount());
ShoppingUp(selectAll);
}
}
@Override
public List<Shopping> selectShow(Shopping s) {
return shop.selectShow(s);
}
@Override
public Shopping selectAll(Shopping s) {
// TODO Auto-generated method stub
return shop.selectAll(s);
}
@Override
public Shopping selectShowtwo(Shopping s) {
// TODO Auto-generated method stub
return shop.selectShowtwo(s);
}
@Override
public void delete(int id) {
shop.delete(id);
}
public interface ProductService {
List<Product> ProductShow();
List<Product> ProductName(String name);
Product selectShowtwo(int id);
}
@Service
@Transactional
public class ProductServiceimpl implements ProductService{
@Autowired
private ProductMapper pro;
@Override
public List<Product> ProductShow() {
// TODO Auto-generated method stub
return pro.ProductShow();
}
@Override
public List<Product> ProductName(String name) {
// TODO Auto-generated method stub
return pro.ProductName(name);
}
@Override
public Product selectShowtwo(int id) {
// TODO Auto-generated method stub
return pro.selectShowtwo(id);
}
}
public interface OrderService {
void orderadd(Order o);
}
@Service
@Transactional
public class OrderServiceimpl implements OrderService{
@Autowired
private OrderMapper order;
@Override
public void orderadd(Order o) {
order.orderadd(o);
}
}
controller层
@Controller
@RequestMapping("shop")
public class ShoppingController {
@Autowired
private ShoppingService service;
@RequestMapping("Shoppingadd")
public String ShoppingAdd(Shopping p,HttpSession session){
User u = (User) session.getAttribute("user");
p.setU(u);
service.listall(p);
return "Pshow";
}
@RequestMapping("show")
@ResponseBody
public List<Shopping> selectShow(Shopping p,HttpSession session){
User u = (User) session.getAttribute("user");
p.setU(u);
List<Shopping> selectShow = service.selectShow(p);
return selectShow;
}
@RequestMapping("add")
public String add(Shopping p){
Shopping selectID = service.selectAll(p);
selectID.setCount(selectID.getCount()+1);
selectID.setPriceCount(selectID.getP().getPrice()*selectID.getCount());
service.ShoppingUp(selectID);
return "Cart";
}
@RequestMapping("jian")
public String jian(Shopping p){
Shopping selectID = service.selectAll(p);
selectID.setCount(selectID.getCount()-1);
selectID.setPriceCount(selectID.getP().getPrice()*selectID.getCount());
service.ShoppingUp(selectID);
return "Cart";
}
@RequestMapping("delete")
public void delete(int id){
service.delete(id);
}
@RequestMapping("deleteall")
public void deleteall(String id){
String[] split = id.split(",");
for (String string : split) {
service.delete(Integer.valueOf(string));
}
}
}
@Controller
@RequestMapping("product")
public class ProductController {
@Autowired
private ProductService service;
@RequestMapping("show")
public String show(HttpSession session){
List<Product> productShow = service.ProductShow();
session.setAttribute("list", productShow);
return "Pshow";
}
@RequestMapping("showName")
public String showName(HttpSession session,String name){
List<Product> productShow = service.ProductName(name);
session.setAttribute("list", productShow);
return "Pshow";
}
@RequestMapping("showtwo")
@ResponseBody
public Product selectTwo(int pid,HttpSession session){
Product selectShowtwo = service.selectShowtwo(pid);
return selectShowtwo;
}
}
@Controller
@RequestMapping("order")
public class OrderController {
@Autowired
private OrderService service;
@RequestMapping("add")
public String add(HttpSession session,String id){
User u = (User) session.getAttribute("user");
String[] split = id.split(",");
for (String string : split) {
Order o = new Order();
o.setU(u);
o.setOid(Integer.valueOf(string));
service.orderadd(o);
}
return "Cart";
}
}
- ssm技术实现购物车
- ssm实战--实现购物车功能
- ssm框架 ajax实现批量删除,和局部添加购物车,购物车总价格
- 购物车实现过程中的技术
- java轻松实现购物车(HashMap技术实现购物车)
- 基于Struts技术的购物车的实现
- Ajax技术实现的购物车,使用Cookie保存。
- Ajax技术实现的购物车,使用Cookie保存。
- 使用session技术来实现网上商城购物车的功能
- 使用session技术实现购物车的功能
- 使用session技术来实现网上商城购物车的功能
- angularjs技术实现购物车加减页面,订单页面
- 使用Servlet技术实现购物车总体介绍
- SSM实现简单的CRUD技术分析
- 购物车的实现
- JSP 购物车实现
- profile实现购物车
- Ajax实现购物车
- 关于javaScript作用域
- 正则基础
- Python判断字符串与大小写转换
- (Boolan) C++面向对象高级编程(一)
- (Boolan) C++面向对象高级编程(二)
- ssm技术实现购物车
- (Boolan) C++面向对象高级编程(三)
- KMP算法详解
- (Boolan) C++ 类型大小和内存分布(虚函数指针、虚表、内存对齐问题)
- Velocity.js的使用
- (Boolan) C++面向对象高级编程(四)
- (Boolan) C++面向对象高级编程(五)
- (Boolan)详解 C++ Operator new\delete、placement new\delete、Array new\delete
- LeetCode_2----Add Two Numbers