package com.mk.controller;
import com.mk.entity.*;
import com.mk.service.LoginService;
import com.mk.service.MainService;
import com.mk.service.impl.MainServiceImpl;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import javax.servlet.http.HttpSession;
import java.net.URI;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Controller
public class MainAction {
private String keyWord;
private int count;
private int orderId;
private int productId;
private Product product;
private Type1 type1;
private List type1Product;
private int addressId;
private String newAddress;
private String serialNumber;
private int zfmoney;
private int page;
private Type2 type2;
private Type3 type3;
private List<News> newslist1;
public Type2 getType2() {
return type2;
}
public void setType2(Type2 type2) {
this.type2 = type2;
}
public Type3 getType3() {
return type3;
}
public void setType3(Type3 type3) {
this.type3 = type3;
}
/*
* 用spring框架后类的对象交给ioc容器处理并用自动注入的方式
* 赋值给引用 如果在代码里面定义的成员变量时用 被ioc容器管理
* 的对象调用放法去设置出初始化值 就会导致服务器 无法启动
* 原因是 那个被使用的对象可能还没有完成自动注入的 时候就被调用
* 服务器报错 无法成功启动 也就无法把错误信息打印出来不会报代码错误 其实是代码错误
* */
@Autowired
private MainService mainService;
private int allPageCount;
public List<News> getNewslist1() {
return newslist1;
}
public void setNewslist1(List<News> newslist1) {
this.newslist1 = newslist1;
}
public int getAllPageCount() {
return allPageCount;
}
public void setAllPageCount(int allPageCount) {
this.allPageCount = allPageCount;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getZfmoney() {
return zfmoney;
}
public void setZfmoney(int zfmoney) {
this.zfmoney = zfmoney;
}
public String getSerialNumber() {
return serialNumber;
}
public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}
public String getNewAddress() {
return newAddress;
}
public void setNewAddress(String newAddress) {
this.newAddress = newAddress;
}
public int getAddressId() {
return addressId;
}
public void setAddressId(int addressId) {
this.addressId = addressId;
}
@Autowired
private LoginService loginService;
public Product getProduct() {
return product;
}
public int getCount() {
return count;
}
public String getKeyWord() {
return keyWord;
}
public void setKeyWord(String keyWord) {
this.keyWord = keyWord;
}
public void setCount(int count) {
this.count = count;
}
public void setProduct(Product product) {
this.product = product;
}
public int getProductId() {
return productId;
}
public void setProductId(int productId) {
this.productId = productId;
}
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public Type1 getType1() {
return type1;
}
public void setType1(Type1 type1) {
this.type1 = type1;
}
public List getType1Product() {
return type1Product;
}
public void setType1Product(List type1Product) {
this.type1Product = type1Product;
}
public String queryProductByType(){
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("st","t");
if (page < 1){
page = 1;
}else if(page > mainService.getType1ProductPageCount(type1,8)){
page = mainService.getType1ProductPageCount(type1,8);
}
allPageCount = mainService.getType1ProductPageCount(type1,8);
type1Product = mainService.getProductByType1Id(type1,page,8);
session.setAttribute("type1Product",type1Product);
return "queryProductByType.ok";
}
public String queryProductByType2(){
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("st","t2");
if (page < 1){
page = 1;
}else if(page > mainService.getType2ProductPageCount(type2,8)){
page = mainService.getType2ProductPageCount(type2,8);
}
allPageCount = mainService.getType2ProductPageCount(type2,8);
type1Product = mainService.getProductByType2Id(type2,page,8);
session.setAttribute("type1Product",type1Product);
return "queryProductByType.ok";
}
public String queryProductByType3(){
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("st","t3");
if (page < 1){
page = 1;
}else if(page > mainService.getType3ProductPageCount(type3,8)){
page = mainService.getType3ProductPageCount(type3,8);
}
allPageCount = mainService.getType3ProductPageCount(type3,8);
type1Product = mainService.getProductByType3Id(type3,page,8);
session.setAttribute("type1Product",type1Product);
return "queryProductByType.ok";
}
public String addToCar(){
HttpSession session = ServletActionContext.getRequest().getSession();
User user = (User) session.getAttribute("user");
//添加购物车后 之前user对象里面保存的order对象是之前的 必须重新查询才能得到新的order
mainService.addToCar(productId,user,count);
updateAllShow(user,session);
return "addToCar.ok";
}
public String deleteCarProduct(){
HttpSession session = ServletActionContext.getRequest().getSession();
User user = (User) session.getAttribute("user");
mainService.deleteCarProduct(orderId);
updateAllShow(user,session);
// StringBuffer path = ServletActionContext.getRequest().getRequestURL();
// System.out.println(path.toString());
return "deleteCarProduct.ok";
}
//当前端用户操作之后用来更新session对象里面的user对象
public void updateAllShow(User user,HttpSession session){
User user1 = loginService.userLogin(user);
Set<Order> orders = user1.getOrders();
//把未支付的订单拿出来把支付了的订单过滤掉
Set<Order> set = new HashSet<>();
String ddh = "";
for(Order order : orders){
if(order.getState()==0){
set.add(order);
}
}
//把订单号存进值栈
for(Order order : orders){
ddh = order.getSerialNumber();
}
serialNumber = ddh;
session.setAttribute("orders",set);
//判断是不是支付后的状态维持
// if(state == 1){
int money = 0;
for (Order order : set){
money+=order.getProduct().getPrice()*order.getCount();
}
session.setAttribute("money",money);
}
// }
public String getProductDetaile(){
product = mainServic
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ssh框架网上购物商城练习包含完整代码和数据库 (865个子文件)
logo.png.1 1KB
logo.png.1 1KB
MainAction.class 10KB
MainAction.class 10KB
MainDaoImpl.class 10KB
MainDaoImpl.class 10KB
MainServiceImpl.class 6KB
MainServiceImpl.class 6KB
LoginAction.class 3KB
LoginAction.class 3KB
User.class 3KB
User.class 3KB
Product.class 3KB
Product.class 3KB
Order.class 2KB
Order.class 2KB
LoginDaoImpl.class 2KB
LoginDaoImpl.class 2KB
MainService.class 2KB
MainService.class 2KB
MainDao.class 2KB
MainDao.class 2KB
Type2.class 2KB
Type2.class 2KB
Type1.class 1KB
Type1.class 1KB
UserAddress.class 1KB
UserAddress.class 1KB
Type3.class 1KB
Type3.class 1KB
News.class 1KB
News.class 1KB
Admin.class 1KB
Admin.class 1KB
LoginServiceImpl.class 1KB
LoginServiceImpl.class 1KB
LoginService.class 333B
LoginService.class 333B
LoginDao.class 321B
LoginDao.class 321B
style.css 110KB
style.css 110KB
ShopShow.css 2KB
ShopShow.css 2KB
head.css 1KB
head.css 1KB
MagicZoom.css 1KB
MagicZoom.css 1KB
Thumbs.db 45KB
Thumbs.db 45KB
er.gif 7KB
er.gif 7KB
b_3.gif 3KB
b_3.gif 3KB
b_5.gif 3KB
b_5.gif 3KB
b_2.gif 2KB
b_2.gif 2KB
b_1.gif 2KB
b_1.gif 2KB
b_6.gif 2KB
b_6.gif 2KB
b_4.gif 2KB
b_4.gif 2KB
btn_sure.gif 2KB
btn_sure.gif 2KB
buy2.gif 2KB
buy2.gif 2KB
add_ad.gif 1KB
add_ad.gif 1KB
z_buy.gif 1KB
z_buy.gif 1KB
buy1.gif 1KB
buy1.gif 1KB
btn_jud.gif 901B
btn_jud.gif 901B
sh_3.gif 407B
sh_3.gif 407B
btn_log.gif 300B
btn_log.gif 300B
pl.gif 297B
pl.gif 297B
sh_5.gif 271B
sh_5.gif 271B
sh_4.gif 258B
sh_4.gif 258B
sh_2.gif 256B
sh_2.gif 256B
sh_1.gif 252B
sh_1.gif 252B
a_link.gif 184B
a_link.gif 184B
jia.gif 93B
jia.gif 93B
jia_b.gif 89B
jia_b.gif 89B
jian.gif 83B
jian.gif 83B
c_t.gif 82B
c_t.gif 82B
共 865 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
- 总承包部2019-06-01运行不出来
散落风尘
- 粉丝: 8
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功