购物车功能
前言
之前修项目的时候经常图片加载不出来,是因为没有给图片做映射的结果,接下来是再卖给图片做映射的步骤,先在 Eclipse 中的Servers文件夹中找到server.xml,打开它滑到最底下找到这一行代码<Context docBase="mvc_book" path="/mvc_book" reloadable="true" source="org.eclipse.jst.jee.server:mvc_book"/>
在他的上面添加一行代码和修改下
<Context docBase="E:/temps/2020/mvc/upload/" path="/uploadImages" />
<Context docBase="mvc_book" path="/" reloadable="true" source="org.eclipse.jst.jee.server:mvc_book"/>
界面结果
购物车
所需的vo(实体类),web,xml配置
vo(实体类)
展示
package com.tang.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 = sendType;
}
public String getPageStr() {
return pageStr;
}
public void setPageStr(String pageStr) {
this.pageStr = pageStr;
}
@Override
public String toString() {
return "ShopGoodsVo [name=" + name + ", price=" + price + ", num=" + num + ", total=" + total + ", consignee="
+ consignee + ", phone=" + phone + ", postalcode=" + postalcode + ", address=" + address + ", sendType="
+ sendType + ", pageStr=" + pageStr + "]";
}
public ShopGoodsVo(String name, float price, int num, float total, String consignee, String phone,
String postalcode, String address, int sendType, String pageStr) {
super();
this.name = name;
this.price = price;
this.num = num;
this.total = total;
this.consignee = consignee;
this.phone = phone;
this.postalcode = postalcode;
this.address = address;
this.sendType = sendType;
this.pageStr = pageStr;
}
public ShopGoodsVo() {
super();
}
}
web
bookAction (书籍名称搜索,书籍类别搜索)
/*
* return null;
* ajax调用的时候,返回json数据,前台页面无刷新功能的时候,无需重定向或者转发
*
* return "findBook";
* 需重定向或者转发
*/
public String search(HttpServletRequest request, HttpServletResponse response) {
PageBean pageBean = new PageBean();
pageBean.setRequest(request);
try {
List<Book> list = this.bookDao.list(book, pageBean);
request.setAttribute("books", list);
request.setAttribute("pageBean", pageBean);
} catch (Exception e) {
e.printStackTrace();
}
return "findBook";
}
<