src/cn/itbaizhan/shop/index/action/IndexAction.java
(完整代码) 1KBpackage cn.itbaizhan.shop.index.action;
import java.util.List;
import cn.itbaizhan.shop.category.service.CategoryService;
import cn.itbaizhan.shop.category.vo.Category;
import cn.itbaizhan.shop.product.service.ProductService;
import cn.itbaizhan.shop.product.vo.Product;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
* 首页访问的Action
*/
public class IndexAction extends ActionSupport{
// 注入一级分类的Service:
private CategoryService categoryService;
// 注入商品的Service
private ProductService productService;
public void setCategoryService(CategoryService categoryService) {
this.categoryService = categoryService;
}
public void setProductService(ProductService productService) {
this.productService = productService;
}
/**
* 执行的访问首页的方法:
*/
public String execute(){
// 查询所有一级分类集合
List<Category> cList = categoryService.findAll();
// 将一级分类存入到Session的范围:
ActionContext.getContext().getSession().put("cList", cList);
// 查询热门商品:
List<Product> hList = productService.findHot();
// 保存到值栈中:
ActionContext.getContext().getValueStack().set("hList", hList);
// 查询最新商品:
List<Product> nList = productService.findNew();
// 保存到值栈中:
ActionContext.getContext().getValueStack().set("nList", nList);
return "index";
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。