package com.briup.web.servlet;
import com.briup.bean.*;
import com.briup.service.IOrderFormService;
import com.briup.service.IOrderLineService;
import com.briup.service.IShopAddressService;
import com.briup.service.IShopCarService;
import com.briup.service.impl.OrderFormServiceImpl;
import com.briup.service.impl.OrderLineServiceImpl;
import com.briup.service.impl.ShopAddressServiceImpl;
import com.briup.service.impl.ShopCarServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
* @author dell
*/
@WebServlet("/ordercommit")
public class OrderCommitServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
IShopAddressService shopAddressService = new ShopAddressServiceImpl();
IOrderFormService orderFormService = new OrderFormServiceImpl();
IOrderLineService orderLineService = new OrderLineServiceImpl();
// 1、接收参数
String receiveName = req.getParameter("receiveName");
String address = req.getParameter("address");
String phone = req.getParameter("phone");
String shipAddId = req.getParameter("shipAddId");
//获取当前登录用户
HttpSession session = req.getSession();
Customer customer = (Customer) session.getAttribute("customer");
// ....接收其他参数
// 判断一下地址是新增还是 原来的地址
// 如果说 前端获取到的receiveName,address,phone不为空的话 就认为要新增地址
// 判断receiveName是否为空 还要判断address phone
ShopAddress shopAddress = new ShopAddress();
if(receiveName.equals("")&&phone.equals("")&&address.equals("")){
//使用旧地址
//没有选择地址情况下
if(shipAddId.equals("")){
resp.sendRedirect("/confirm");
return;
}else{
Integer addId = Integer.valueOf(shipAddId);
shopAddress.setId(addId);
}
}else{
// 不为空为新地址
shopAddress.setAddress(address);
shopAddress.setReceiveName(receiveName);
shopAddress.setPhone(phone);
shopAddress.setCustomer(customer);
shopAddressService.saveAddress(shopAddress);
}
// 可以通过接收参数的形式获取旧地址的id
// 通过这个地址id查询地址信息(拿到id之后new ShopAddress只把id放进去)
// 开始准备一个OrderForm对象(时间可以直接newDate)
List<ShopCar> shopCarList = (List<ShopCar>) session.getAttribute("confrim");
Double total = 0.0;
for (ShopCar shopCar : shopCarList) {
total = total + (shopCar.getNum()*shopCar.getBook().getPrice());
}
OrderForm orderForm = new OrderForm();
orderForm.setCost(total);
orderForm.setOrderdate(new Date());
orderForm.setShopAddress(shopAddress);
orderForm.setCustomer(customer);
// 并且调用对应的方法saveOrderForm(需要selectkey)
orderFormService.saveOrderForm(orderForm);
// 把他对应的订单项存入数据库当中(需要订单表的id)
for (ShopCar shopCar : shopCarList) {
OrderLine orderLine = new OrderLine();
orderLine.setBook(shopCar.getBook());
orderLine.setNum(Long.valueOf(shopCar.getNum()));
orderLine.setCost(shopCar.getNum()*shopCar.getBook().getPrice());
orderLine.setOrderForm(orderForm);
orderLineService.saveOrderLine(orderLine);
}
// 结束
resp.sendRedirect("/orderList");
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
/* @Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//接收参数
String receiveName = req.getParameter("receiveName");
String address = req.getParameter("address");
String phone = req.getParameter("phone");
String shipAddId = req.getParameter("shipAddId");
//获取当前登录用户
Customer customer = (Customer) req.getSession().getAttribute("customer");
//实例化对地址操作的对象
IShopAddressService iShopAddressService = new ShopAddressServiceImpl();
ShopAddress shopAddressById=new ShopAddress();
//判断是否为新增地址
if (receiveName.equals("") && address.equals("") && phone.equals("")){
//查询当前选中的旧地址id
if (shipAddId.equals("")){
resp.sendRedirect("/confirm.jsp");
}else {
//shopAddressById = iShopAddressService.findShopAddressById(Integer.parseInt(shipAddId));
shopAddressById .setId(Integer.parseInt(shipAddId));
System.out.println(shopAddressById);
}
}else {
//如果前端获取到数据不为空的话,就认为是新增地址,如果都为空,就选择旧地址,就地址可以通过接收shipAddId参数的形式获取旧地址的id,通过对应方法查到当前的地址信息
shopAddressById=new ShopAddress(receiveName,address,phone,customer);
//把新的地址存入数据库
iShopAddressService.saveAddress(shopAddressById);
System.out.println(shopAddressById);
}
//获取当前所有的订单信息计算价格
double total =0;
List<ShopCar> confrim = (List<ShopCar>) req.getSession().getAttribute("confrim");
for (ShopCar shopCar : confrim) {
total=total+shopCar.getBook().getPrice()*shopCar.getNum();
}
System.out.println(total);
//准备一个orderform对象,往表里面塞对象,时间可以直接newdate,然后调用方法保存订单信息
OrderForm orderForm = new OrderForm(total,new Date(),customer,shopAddressById);
System.out.println(orderForm);
//把orderform存入数据库
IOrderFormService iOrderFormService = new OrderFormServiceImpl();
iOrderFormService.saveOrderForm(orderForm);
//把对应的订单项存入数据库当中(orderline)
for (ShopCar shopCar : confrim) {
IOrderLineService iOrderLineService = new OrderLineServiceImpl();
OrderLine orderLine = new OrderLine();
orderLine.setBook(shopCar.getBook());
orderLine.setNum((long) shopCar.getNum());
orderLine.setCost((shopCar.getBook().getPrice()*shopCar.getNum()));
orderLine.setOrderForm(orderForm);
System.out.println(orderLine);
iOrderLineService.saveOrderLine(orderLine);
}
}*/
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java写的一个网上购书系统源码.zip
共514个文件
png:190个
class:84个
jpg:72个
需积分: 9 0 下载量 154 浏览量
2022-10-13
13:12:12
上传
评论 1
收藏 11.97MB ZIP 举报
温馨提示
该项目是一个网上购书系统, 方便用户网上购书,用户可以登录该系统选择自己喜欢的书籍进行购买。该项目各个模块均使用三层架构来实现,使用idea开发工具开发,使用servlet处理请求,jsp做前端响应,oracle做数据存储。
资源详情
资源评论
资源推荐
收起资源包目录
Java写的一个网上购书系统源码.zip (514个子文件)
OrderCommitServlet.class 5KB
OrderCommitServlet.class 5KB
Book.class 3KB
Book.class 3KB
OrderForm.class 3KB
OrderForm.class 3KB
Customer.class 3KB
Customer.class 3KB
LoginServlet.class 2KB
LoginServlet.class 2KB
ShopAddress.class 2KB
ShopAddress.class 2KB
OrderLine.class 2KB
OrderLine.class 2KB
RegisterServlet.class 2KB
RegisterServlet.class 2KB
ShopCar.class 2KB
ShopCar.class 2KB
ShopCarAddServlet.class 2KB
ShopCarAddServlet.class 2KB
ShopCarCommitServlet.class 2KB
ShopCarCommitServlet.class 2KB
ShopCarUpdateServlet.class 2KB
ShopCarUpdateServlet.class 2KB
Category.class 2KB
Category.class 2KB
shopCarDeleteServlet.class 2KB
shopCarDeleteServlet.class 2KB
ShopCarServiceImpl.class 2KB
ShopCarServiceImpl.class 2KB
CustomerServiceImpl.class 2KB
CustomerServiceImpl.class 2KB
OrderListServlet.class 2KB
OrderListServlet.class 2KB
BookInfo.class 2KB
BookInfo.class 2KB
IndexLisener.class 2KB
IndexLisener.class 2KB
EncodingFilter.class 2KB
EncodingFilter.class 2KB
AddAddressServlet.class 2KB
AddAddressServlet.class 2KB
ShopAddressServiceImpl.class 2KB
ShopAddressServiceImpl.class 2KB
OrderFormServiceImpl.class 2KB
OrderFormServiceImpl.class 2KB
MyBatisSqlSessionFactory.class 1KB
MyBatisSqlSessionFactory.class 1KB
BookServiceImpl.class 1KB
BookServiceImpl.class 1KB
OrderLineServiceImpl.class 1KB
OrderLineServiceImpl.class 1KB
LoginOutServlet.class 1KB
LoginOutServlet.class 1KB
CategoryServiceImpl.class 971B
CategoryServiceImpl.class 971B
ShopCarMapper.class 696B
ShopCarMapper.class 696B
IShopCarService.class 681B
IShopCarService.class 681B
ShopAddressMapper.class 539B
ShopAddressMapper.class 539B
IOrderFormService.class 488B
IOrderFormService.class 488B
OrderFormMapper.class 483B
OrderFormMapper.class 483B
OrderLineMapper.class 472B
OrderLineMapper.class 472B
IShopAddressService.class 439B
IShopAddressService.class 439B
BookMapper.class 403B
BookMapper.class 403B
CustomerMapper.class 364B
CustomerMapper.class 364B
IOrderLineService.class 350B
IOrderLineService.class 350B
ICustomerService.class 340B
ICustomerService.class 340B
IBookService.class 299B
IBookService.class 299B
ICategoryService.class 247B
ICategoryService.class 247B
CategoryMapper.class 239B
CategoryMapper.class 239B
style.css 26KB
style.css 26KB
orderSure.css 7KB
orderSure.css 7KB
order.css 7KB
order.css 7KB
fullCar.css 6KB
fullCar.css 6KB
apply.css 3KB
apply.css 3KB
emptyCar.css 3KB
emptyCar.css 3KB
icons.css 2KB
icons.css 2KB
common.css 2KB
common.css 2KB
共 514 条
- 1
- 2
- 3
- 4
- 5
- 6
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6727
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0