步骤 2 : 模仿和排错 步骤 3 : 界面效果 步骤 4 : Action4Pojo 步骤 5 : ForeAction.buy() 步骤 6 : buy.jsp 步骤 7 : buyPage.jsp
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.action;
import java.util.List;
import com.how2java.tmall.pojo.Category;
import com.how2java.tmall.pojo.Order;
import com.how2java.tmall.pojo.OrderItem;
import com.how2java.tmall.pojo.Product;
import com.how2java.tmall.pojo.ProductImage;
import com.how2java.tmall.pojo.Property;
import com.how2java.tmall.pojo.PropertyValue;
import com.how2java.tmall.pojo.Review;
import com.how2java.tmall.pojo.User;
public class Action4Pojo extends Action4Pagination {
protected Category category;
protected Property property;
protected Product product;
protected ProductImage productImage;
protected PropertyValue propertyValue;
protected User user;
protected Order order;
protected Review review;
protected OrderItem orderItem;
protected List<Category> categorys;
protected List<Property> propertys;
protected List<Product> products;
protected List<ProductImage> productSingleImages;
protected List<ProductImage> productDetailImages;
protected List<PropertyValue> propertyValues;
protected List<User> users;
protected List<Order> orders;
protected List<Review> reviews;
protected List<OrderItem> orderItems;
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public List<Category> getCategorys() {
return categorys;
}
public void setCategorys(List<Category> categorys) {
this.categorys = categorys;
}
public Property getProperty() {
return property;
}
public void setProperty(Property property) {
this.property = property;
}
public List<Property> getPropertys() {
return propertys;
}
public void setPropertys(List<Property> propertys) {
this.propertys = propertys;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public ProductImage getProductImage() {
return productImage;
}
public void setProductImage(ProductImage productImage) {
this.productImage = productImage;
}
public List<ProductImage> getProductSingleImages() {
return productSingleImages;
}
public void setProductSingleImages(List<ProductImage> productSingleImages) {
this.productSingleImages = productSingleImages;
}
public List<ProductImage> getProductDetailImages() {
return productDetailImages;
}
public void setProductDetailImages(List<ProductImage> productDetailImages) {
this.productDetailImages = productDetailImages;
}
public PropertyValue getPropertyValue() {
return propertyValue;
}
public void setPropertyValue(PropertyValue propertyValue) {
this.propertyValue = propertyValue;
}
public List<PropertyValue> getPropertyValues() {
return propertyValues;
}
public void setPropertyValues(List<PropertyValue> propertyValues) {
this.propertyValues = propertyValues;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public List<Order> getOrders() {
return orders;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
}
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
@Action("forebuy")
public String buy() {
orderItems = new ArrayList<>();
for (int oiid : oiids) {
OrderItem oi= (OrderItem) orderItemService.get(oiid);
total +=oi.getProduct().getPromotePrice()*oi.getNumber();
orderItems.add(oi);
productImageService.setFirstProdutImage(oi.getProduct());
}
ActionContext.getContext().getSession().put("orderItems", orderItems);
return "buy.jsp";
}
package com.how2java.tmall.action;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.web.util.HtmlUtils;
import com.how2java.tmall.comparator.ProductAllComparator;
import com.how2java.tmall.comparator.ProductDateComparator;
import com.how2java.tmall.comparator.ProductPriceComparator;
import com.how2java.tmall.comparator.ProductReviewComparator;
import com.how2java.tmall.comparator.ProductSaleCountComparator;
import com.how2java.tmall.pojo.OrderItem;
import com.how2java.tmall.pojo.Product;
import com.how2java.tmall.pojo.User;
import com.how2java.tmall.service.ProductImageService;
import com.opensymphony.xwork2.ActionContext;
public class ForeAction extends Action4Result {
@Action("forebuy")
public String buy() {
orderItems = new ArrayList<>();
for (int oiid : oiids) {
OrderItem oi= (OrderItem) orderItemService.get(oiid);
total +=oi.getProduct().getPromotePrice()*oi.getNumber();
orderItems.add(oi);
productImageService.setFirstProdutImage(oi.getProduct());
}
ActionContext.getContext().getSession().put("orderItems", orderItems);
return "buy.jsp";
}
@Action("forebuyone")
public String buyone() {
User user =(User) ActionContext.getContext().getSession().get("user");
boolean found = false;
List<OrderItem> ois = orderItemService.list("user",user,"order", null);
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==product.getId()){
oi.setNumber(oi.getNumber()+num);
orderItemService.update(oi);
found = true;
oiid = oi.getId();
break;
}
}
if(!found){
OrderItem oi = new OrderItem();
oi.setUser(user);
oi.setNumber(num);
oi.setProduct(product);
orderItemService.save(oi);
oiid = oi.getId();
}
return "buyPage";
}
@Action("foresearch")
public String search(){
products= productService.search(keyword,0,20);
productService.setSaleAndReviewNumber(products);
for (Product product : products)
productImageService.setFirstProdutImage(product);
return "searchResult.jsp";
}
@Action("forecategory")
public String category(){
t2p(category);
productService.fill(category);
productService.setSaleAndReviewNumber(category.getProducts());
if(null!=sort){
switch(sort){
case "review":
Collections.sort(category.getProducts(),new ProductReviewComparator());
break;
case "date" :
Collections.sort(category.getProducts(),new ProductDateComparator());
break;
case "saleCount" :
Collections.sort(category.getProducts(),new ProductSaleCountComparator());
break;
case "price":
Collections.sort(category.getProducts(),new ProductPriceComparator());
break;
case "all":
Collections.sort(category.getProducts(),new ProductAllComparator());
break;
}
}
return "category.jsp";
}
@Action("foreloginAjax")
public String loginAjax() {
user.setName(HtmlUtils.htmlEscape(user.getName()));
User user_session = userService.get(user.getName(),user.getPassword());
if(null==user_session)
return "fail.jsp";
ActionContext.getContext().getSession().put("user", user_session);
return "success.jsp";
}
@Action("forecheckLogin")
public String checkLogin() {
User u =(User) ActionContext.getContext().getSession().get("user");
if(null==u)
return "fail.jsp";
else
return "success.jsp";
}
@Action("foreproduct")
public String product() {
t2p(product);
productImageService.setFirstProdutImage(product);
productSingleImages = productImageService.list("product",product,"type", ProductImageService.type_single);
productDetailImages = productImageService.list("product",product,"type", ProductImageService.type_detail);
product.setProductSingleImages(productSingleImages);
product.setProductDetailImages(productDetailImages);
propertyValues = propertyValueService.listByParent(product);
reviews = reviewService.listByParent(product);
productService.setSaleAndReviewNumber(product);
return "product.jsp";
}
@Action("forelogout")
public String logout() {
ActionContext.getContext().getSession().remove("user");
return "homePage";
}
@Action("forelogin")
public String login() {
user.setName(HtmlUtils.htmlEscape(user.getName()));
User user_session = userService.get(user.getName(),user.getPassword());
if(null==user_session){
msg= "账号密码错误";
return "login.jsp";
}
ActionContext.getContext().getSession().put("user", user_session);
return "homePage";
}
@Action("foreregister")
public String register() {
user.setName(HtmlUtils.htmlEscape(user.getName()));
boolean exist = userService.isExist(user.getName());
if(exist){
msg = "用户名已经被使用,不能使用";
return "register.jsp";
}
userService.save(user);
return "registerSuccessPage";
}
@Action("forehome")
public String home() {
categorys = categoryService.list();
productService.fill(categorys);
productService.fillByRow(categorys);
return "home.jsp";
}
}
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@include file="include/header.jsp"%>
<%@include file="include/top.jsp"%>
<%@include file="include/cart/buyPage.jsp"%>
<%@include file="include/footer.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%> <%@include file="include/header.jsp"%> <%@include file="include/top.jsp"%> <%@include file="include/cart/buyPage.jsp"%> <%@include file="include/footer.jsp"%>
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<div class="buyPageDiv">
<form action="forecreateOrder" method="post">
<div class="buyFlow">
<img class="pull-left" src="img/site/simpleLogo.png">
<img class="pull-right" src="img/site/buyflow.png">
<div style="clear:both"></div>
</div>
<div class="address">
<div class="addressTip">输入收货地址</div>
<div>
<table class="addressTable">
<tr>
<td class="firstColumn">详细地址<span class="redStar">*</span></td>
<td><textarea name="order.address" placeholder="建议您如实填写详细收货地址,例如接到名称,门牌好吗,楼层和房间号等信息"></textarea></td>
</tr>
<tr>
<td>邮政编码</td>
<td><input name="order.post" placeholder="如果您不清楚邮递区号,请填写000000" type="text"></td>
</tr>
<tr>
<td>收货人姓名<span class="redStar">*</span></td>
<td><input name="order.receiver" placeholder="长度不超过25个字符" type="text"></td>
</tr>
<tr>
<td>手机号码 <span class="redStar">*</span></td>
<td><input name="order.mobile" placeholder="请输入11位手机号码" type="text"></td>
</tr>
</table>
</div>
</div>
<div class="productList">
<div class="productListTip">确认订单信息</div>
<table class="productListTable">
<thead>
<tr>
<th colspan="2" class="productListTableFirstColumn">
<img class="tmallbuy" src="img/site/tmallbuy.png">
<a class="marketLink" href="#nowhere">店铺:天猫店铺</a>
<a class="wangwanglink" href="#nowhere"> <span class="wangwangGif"></span> </a>
</th>
<th>单价</th>
<th>数量</th>
<th>小计</th>
<th>配送方式</th>
</tr>
<tr class="rowborder">
<td colspan="2" ></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</thead>
<tbody class="productListTableTbody">
<c:forEach items="${orderItems}" var="oi" varStatus="st" >
<tr class="orderItemTR">
<td class="orderItemFirstTD"><img class="orderItemImg" src="img/productSingle_middle/${oi.product.firstProductImage.id}.jpg"></td>
<td class="orderItemProductInfo">
<a href="foreproduct?product.id=${oi.product.id}" class="orderItemProductLink">
${oi.product.name}
</a>
<img src="img/site/creditcard.png" title="支持信用卡支付">
<img src="img/site/7day.png" title="消费者保障服务,承诺7天退货">
<img src="img/site/promise.png" title="消费者保障服务,承诺如实描述">
</td>
<td>
<span class="orderItemProductPrice">¥<fmt:formatNumber type="number" value="${oi.product.promotePrice}" minFractionDigits="2"/></span>
</td>
<td>
<span class="orderItemProductNumber">${oi.number}</span>
</td>
<td><span class="orderItemUnitSum">
¥<fmt:formatNumber type="number" value="${oi.number*oi.product.promotePrice}" minFractionDigits="2"/>
</span></td>
<c:if test="${st.count==1}">
<td rowspan="5" class="orderItemLastTD">
<label class="orderItemDeliveryLabel">
<input type="radio" value="" checked="checked">
普通配送
</label>
<select class="orderItemDeliverySelect" class="form-control">
<option>快递 免邮费</option>
</select>
</td>
</c:if>
</tr>
</c:forEach>
</tbody>
</table>
<div class="orderItemSumDiv">
<div class="pull-left">
<span class="leaveMessageText">给卖家留言:</span>
<span>
<img class="leaveMessageImg" src="img/site/leaveMessage.png">
</span>
<span class="leaveMessageTextareaSpan">
<textarea name="order.userMessage" class="leaveMessageTextarea"></textarea>
<div>
<span>还可以输入200个字符</span>
</div>
</span>
</div>
<span class="pull-right">店铺合计(含运费): ¥<fmt:formatNumber type="number" value="${total}" minFractionDigits="2"/></span>
</div>
</div>
<div class="orderItemTotalSumDiv">
<div class="pull-right">
<span>实付款:</span>
<span class="orderItemTotalSumSpan">¥<fmt:formatNumber type="number" value="${total}" minFractionDigits="2"/></span>
</div>
</div>
<div class="submitOrderDiv">
<button type="submit" class="submitOrderButton">提交订单</button>
</div>
</form>
</div>
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2019-11-20
为什么int类型的oiid可以直接传值给数组oiids
2 个答案
来载 跳转到问题位置 答案时间:2019-11-21 但是看起来怎么好像是oiids(数组)=${oiid}(int),可以这样跨类型赋值吗
location = "forebuy?oiids=${oiid} how2j 跳转到问题位置 答案时间:2019-11-20 因为后续会传多个oiid, 这里设计的时候,就是考虑到将来要接受多个,所以用数组来接受。
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|