步骤 2 : 模仿和排错 步骤 3 : 界面效果 步骤 4 : 评价产品页面 步骤 5 : 提交评价
增值内容,请先登录
完整的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项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
@Action("forereview")
public String review() {
t2p(order);
orderItemService.fill(order);
product = order.getOrderItems().get(0).getProduct();
reviews = reviewService.listByParent(product);
productService.setSaleAndReviewNumber(product);
return "review.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/simpleSearch.jsp"%>
<%@include file="include/cart/reviewPage.jsp"%>
<%@include file="include/footer.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<div class="reviewDiv">
<div class="reviewProductInfoDiv">
<div class="reviewProductInfoImg"><img width="400px" height="400px" src="img/productSingle/${product.firstProductImage.id}.jpg"></div>
<div class="reviewProductInfoRightDiv">
<div class="reviewProductInfoRightText">
${product.name}
</div>
<table class="reviewProductInfoTable">
<tr>
<td width="75px">价格:</td>
<td><span class="reviewProductInfoTablePrice">¥<fmt:formatNumber type="number" value="${product.originalPrice}" minFractionDigits="2"/></span> 元 </td>
</tr>
<tr>
<td>配送</td>
<td>快递: 0.00</td>
</tr>
<tr>
<td>月销量:</td>
<td><span class="reviewProductInfoTableSellNumber">${product.saleCount}</span> 件</td>
</tr>
</table>
<div class="reviewProductInfoRightBelowDiv">
<span class="reviewProductInfoRightBelowImg"><img1 src="img/site/reviewLight.png"></span>
<span class="reviewProductInfoRightBelowText" >现在查看的是 您所购买商品的信息
于<fmt:formatDate value="${order.createDate}" pattern="yyyy年MM月dd"/>下单购买了此商品 </span>
</div>
</div>
<div style="clear:both"></div>
</div>
<div class="reviewStasticsDiv">
<div class="reviewStasticsLeft">
<div class="reviewStasticsLeftTop"></div>
<div class="reviewStasticsLeftContent">累计评价 <span class="reviewStasticsNumber"> ${product.reviewCount}</span></div>
<div class="reviewStasticsLeftFoot"></div>
</div>
<div class="reviewStasticsRight">
<div class="reviewStasticsRightEmpty"></div>
<div class="reviewStasticsFoot"></div>
</div>
</div>
<c:if test="${param.showonly==true}">
<div class="reviewDivlistReviews">
<c:forEach items="${reviews}" var="r">
<div class="reviewDivlistReviewsEach">
<div class="reviewDate"><fmt:formatDate value="${r.createDate}" pattern="yyyy-MM-dd"/></div>
<div class="reviewContent">${r.content}</div>
<div class="reviewUserInfo pull-right">${r.user.anonymousName}<span class="reviewUserInfoAnonymous">(匿名)</span></div>
</div>
</c:forEach>
</div>
</c:if>
<c:if test="${param.showonly!=true}">
<div class="makeReviewDiv">
<form method="post" action="foredoreview">
<div class="makeReviewText">其他买家,需要你的建议哦!</div>
<table class="makeReviewTable">
<tr>
<td class="makeReviewTableFirstTD">评价商品</td>
<td><textarea name="review.content"></textarea></td>
</tr>
</table>
<div class="makeReviewButtonDiv">
<input type="hidden" name="order.id" value="${order.id}">
<input type="hidden" name="product.id" value="${product.id}">
<button type="submit">提交评价</button>
</div>
</form>
</div>
</c:if>
</div>
package com.how2java.tmall.action;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.xwork.math.RandomUtils;
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.OrderService;
import com.how2java.tmall.service.ProductImageService;
import com.opensymphony.xwork2.ActionContext;
public class ForeAction extends Action4Result {
@Action("forereview")
public String review() {
t2p(order);
orderItemService.fill(order);
product = order.getOrderItems().get(0).getProduct();
reviews = reviewService.listByParent(product);
productService.setSaleAndReviewNumber(product);
return "review.jsp";
}
@Action("foredeleteOrder")
public String deleteOrder(){
t2p(order);
order.setStatus(OrderService.delete);
orderService.update(order);
return "success.jsp";
}
@Action("foreorderConfirmed")
public String orderConfirmed() {
t2p(order);
order.setStatus(OrderService.waitReview);
order.setConfirmDate(new Date());
orderService.update(order);
return "orderConfirmed.jsp";
}
@Action("foreconfirmPay")
public String confirmPay() {
t2p(order);
orderItemService.fill(order);
return "confirmPay.jsp";
}
@Action("forebought")
public String bought() {
User user =(User) ActionContext.getContext().getSession().get("user");
orders= orderService.listByUserWithoutDelete(user);
orderItemService.fill(orders);
return "bought.jsp";
}
@Action("forepayed")
public String payed() {
t2p(order);
order.setStatus(OrderService.waitDelivery);
order.setPayDate(new Date());
orderService.update(order);
return "payed.jsp";
}
@Action("forealipay")
public String forealipay(){
return "alipay.jsp";
}
@Action("forecreateOrder")
public String createOrder(){
List<OrderItem> ois= (List<OrderItem>) ActionContext.getContext().getSession().get("orderItems");
if(ois.isEmpty())
return "login.jsp";
User user =(User) ActionContext.getContext().getSession().get("user");
String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000);
order.setOrderCode(orderCode);
order.setCreateDate(new Date());
order.setUser(user);
order.setStatus(OrderService.waitPay);
total = orderService.createOrder(order, ois);
return "alipayPage";
}
@Action("foredeleteOrderItem")
public String deleteOrderItem(){
orderItemService.delete(orderItem);
return "success.jsp";
}
@Action("forechangeOrderItem")
public String changeOrderItem() {
User user =(User) ActionContext.getContext().getSession().get("user");
List<OrderItem> ois = orderItemService.list("user",user,"order", null);
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==product.getId()){
oi.setNumber(num);
orderItemService.update(oi);
break;
}
}
return "success.jsp";
}
@Action("forecart")
public String cart() {
User user =(User) ActionContext.getContext().getSession().get("user");
orderItems = orderItemService.list("user",user,"order", null);
for (OrderItem orderItem : orderItems)
productImageService.setFirstProdutImage(orderItem.getProduct());
return "cart.jsp";
}
@Action("foreaddCart")
public String addCart() {
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;
break;
}
}
if(!found){
OrderItem oi = new OrderItem();
oi.setUser(user);
oi.setNumber(num);
oi.setProduct(product);
orderItemService.save(oi);
}
return "success.jsp";
}
@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项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
@Action("foredoreview")
public String doreview() {
t2p(order);
t2p(product);
order.setStatus(OrderService.finish);
String content = review.getContent();
content = HtmlUtils.htmlEscape(content);
User user =(User) ActionContext.getContext().getSession().get("user");
review.setContent(content);
review.setProduct(product);
review.setCreateDate(new Date());
review.setUser(user);
reviewService.saveReviewAndUpdateOrderStatus(review,order);
showonly = true;
return "reviewPage";
}
<c:if test="${param.showonly==true}">
<div class="reviewDivlistReviews">
<c:forEach items="${reviews}" var="r">
<div class="reviewDivlistReviewsEach">
<div class="reviewDate"><fmt:formatDate value="${r.createDate}" pattern="yyyy-MM-dd"/></div>
<div class="reviewContent">${r.content}</div>
<div class="reviewUserInfo pull-right">${r.user.anonymousName}<span class="reviewUserInfoAnonymous">(匿名)</span></div>
</div>
</c:forEach>
</div>
</c:if>
package com.how2java.tmall.action;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.xwork.math.RandomUtils;
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.OrderService;
import com.how2java.tmall.service.ProductImageService;
import com.opensymphony.xwork2.ActionContext;
public class ForeAction extends Action4Result {
@Action("foredoreview")
public String doreview() {
t2p(order);
t2p(product);
order.setStatus(OrderService.finish);
String content = review.getContent();
content = HtmlUtils.htmlEscape(content);
review.setContent(content);
User user =(User) ActionContext.getContext().getSession().get("user");
review.setContent(content);
review.setProduct(product);
review.setCreateDate(new Date());
review.setUser(user);
reviewService.saveReviewAndUpdateOrderStatus(review,order);
showonly = true;
return "reviewPage";
}
@Action("forereview")
public String review() {
t2p(order);
orderItemService.fill(order);
product = order.getOrderItems().get(0).getProduct();
reviews = reviewService.listByParent(product);
productService.setSaleAndReviewNumber(product);
return "review.jsp";
}
@Action("foredeleteOrder")
public String deleteOrder(){
t2p(order);
order.setStatus(OrderService.delete);
orderService.update(order);
return "success.jsp";
}
@Action("foreorderConfirmed")
public String orderConfirmed() {
t2p(order);
order.setStatus(OrderService.waitReview);
order.setConfirmDate(new Date());
orderService.update(order);
return "orderConfirmed.jsp";
}
@Action("foreconfirmPay")
public String confirmPay() {
t2p(order);
orderItemService.fill(order);
return "confirmPay.jsp";
}
@Action("forebought")
public String bought() {
User user =(User) ActionContext.getContext().getSession().get("user");
orders= orderService.listByUserWithoutDelete(user);
orderItemService.fill(orders);
return "bought.jsp";
}
@Action("forepayed")
public String payed() {
t2p(order);
order.setStatus(OrderService.waitDelivery);
order.setPayDate(new Date());
orderService.update(order);
return "payed.jsp";
}
@Action("forealipay")
public String forealipay(){
return "alipay.jsp";
}
@Action("forecreateOrder")
public String createOrder(){
List<OrderItem> ois= (List<OrderItem>) ActionContext.getContext().getSession().get("orderItems");
if(ois.isEmpty())
return "login.jsp";
User user =(User) ActionContext.getContext().getSession().get("user");
String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000);
order.setOrderCode(orderCode);
order.setCreateDate(new Date());
order.setUser(user);
order.setStatus(OrderService.waitPay);
total = orderService.createOrder(order, ois);
return "alipayPage";
}
@Action("foredeleteOrderItem")
public String deleteOrderItem(){
orderItemService.delete(orderItem);
return "success.jsp";
}
@Action("forechangeOrderItem")
public String changeOrderItem() {
User user =(User) ActionContext.getContext().getSession().get("user");
List<OrderItem> ois = orderItemService.list("user",user,"order", null);
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==product.getId()){
oi.setNumber(num);
orderItemService.update(oi);
break;
}
}
return "success.jsp";
}
@Action("forecart")
public String cart() {
User user =(User) ActionContext.getContext().getSession().get("user");
orderItems = orderItemService.list("user",user,"order", null);
for (OrderItem orderItem : orderItems)
productImageService.setFirstProdutImage(orderItem.getProduct());
return "cart.jsp";
}
@Action("foreaddCart")
public String addCart() {
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;
break;
}
}
if(!found){
OrderItem oi = new OrderItem();
oi.setUser(user);
oi.setNumber(num);
oi.setProduct(product);
orderItemService.save(oi);
}
return "success.jsp";
}
@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";
}
}
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2020-12-04
站长,评价页面显示的价格应该要是促销价吧。。。。
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2019-05-09
站长,为什么reviews集合在访问“forereview"已经被拿出来了,后面我提交新的评价还能够显示出来呢?
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2019-04-18
关于步骤5
2018-07-27
步骤5
2018-05-22
这里的ReviewService之前好像没加saveReviewAndUpdateOrderStatus方法
提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 2 条以前的提问,请 点击查看
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|