购物车功能(一)

这篇博客主要介绍了如何实现门户书籍搜索后台功能,包括根据书名和类别查询。接着,讲述了创建购物车前端页面,定义购物车实体类ShopGoodsVo,并实现加入购物车的点击事件。最后,详细讲解了购物车功能的业务逻辑层编码和配置,以及从搜索界面到购物车界面的跳转逻辑。
摘要由CSDN通过智能技术生成

一、门户书籍搜索后台功能实现

在这里插入图片描述
实现界面上的搜索功能,可以根据书名查询,也可以根据类别查询,名字查询已经做过,所以只需要在查询的方法上加一个条件。

public List<Book> list(Book book,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
   
		String name = book.getName();
		String sql = "select * from t_easyui_book where true ";
		long cid=book.getCid();
		if(StringUtils.isNotBlank(name)) {
   
			sql += " and name like '%"+name+"%'";
		}
		if(StringUtils.isNotBlank(name)) {
   
			sql += " and cid ="+cid;
		}
		return super.executeQuery(sql, Book.class, pageBean);
	}

然而在业务逻辑层里的datagrid方法不能用了,因为我们用forEach遍历做信息展示就直接加载数据、跳转页面,就不能用线程的方式了。所以我们要重新写一个方法

public String search(HttpServletRequest req,HttpServletResponse resp) {
   
		PageBean pageBean = new PageBean();
		pageBean.setRequest(req);
		try {
   
			List<Book> list = this.bookDao.list(book, pageBean);
//			因为search做遍历
			req.setAttribute("books", list);
		} catch (InstantiationException | IllegalAccessException | SQLException e) {
   
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "search";
		
	}

再配置一下

<action path="/book" type="com.meng.web.BookAction">
	<forward name="search" path="/search.jsp" redirect="false" />
	</action>

新建一个js,这个是分类列表

<script src="${pageContext.request.contextPath}/static/js/common.js"></script>

添加事件,

function search(){
   
				location.href="${pageContext.request.contextPath }/book.action?methodName=search&name="+$("#book_name").val();
			}

index.js

function searchByType(cid){
   
	var ctx = $("#ctx").val();	
	location.href=ctx+"/book.action?methodName=search&cid="+cid;
}

在这里插入图片描述

二、加入购物车前端页面

需要准备购物车的字段(实体类ShopGoodsVo),放在vo包里

package com.meng.vo;


import java.util.Objects;


public class ShopGoodsVo {
   
//    购物车列表订单项所需数据
    private String name;
    private float price;
    private int num;
    private float total;

//    提交订单所需数据
    private String consignee;
    private String phone;
    private String postalcode;
    private String address;
    private int sendType;

//    页面的所有传参字符串
    private String pageStr;

    @Override
    public boolean equals(Object o) {
   
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ShopGoodsVo that = (ShopGoodsVo) o;
        return Float.compare(that.price, price) == 0 &&
                num == that.num &&
                Float.compare(that.total, total) == 0 &&
                Objects.equals(name, that.name);
    }

    @Override
    public int hashCode() {
   
        return Objects.hash(name, price, num, total);
    }

	public String getName() {
   
		return name;
	}

	public void setName(String name) {
   
		this.name = name;
	}

	public float getPrice() {
   
		return price;
	}

	public void setPrice(float price) {
   
		this.price = price;
	}

	public int getNum() {
   
		return num;
	}

	public void setNum(int num) {
   
		this.num = num;
	}

	public float getTotal() {
   
		return total;
	}

	public void setTotal(float total) {
   
		this.total = total;
	}

	public String getConsignee() {
   
		return consignee;
	}

	public void setConsignee(String consignee) {
   
		this.consignee = consignee;
	}

	public String getPhone() {
   
		return phone;
	}

	public void setPhone(String phone) {
   
		this.phone = phone;
	}

	public String getPostalcode() {
   
		return postalcode;
	}

	public void setPostalcode(String postalcode) {
   
		this.postalcode = postalcode;
	}

	public String getAddress() {
   
		return address;
	}

	public void setAddress(String address) {
   
		this.address = address;
	}

	public int getSendType() {
   
		return sendType;
	}

	public void setSendType(int sendType) {
   
		this.sendType 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值