1.创建表:(一级分类)
CREATE TABLE `category` ( `cid` int(11) NOT NULL AUTO_INCREMENT, `cname` varchar(255) DEFAULT NULL, PRIMARY KEY (`cid`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8; INSERT INTO `category` VALUES (‘1‘, ‘女装男装‘); INSERT INTO `category` VALUES (‘2‘, ‘鞋靴箱包‘); INSERT INTO `category` VALUES (‘3‘, ‘运动户外‘); INSERT INTO `category` VALUES (‘4‘, ‘珠宝配饰‘); INSERT INTO `category` VALUES (‘5‘, ‘手机数码‘); INSERT INTO `category` VALUES (‘6‘, ‘家电办公‘); INSERT INTO `category` VALUES (‘7‘, ‘护肤彩妆‘);
2.首页上的查询所有一级分类
IndexAction
@Override /** * 访问首页的时候执行的方法: */ public String execute() throws Exception { // 查询所有一级分类 List<Category> cList = categoryService.findAll(); // 查询热门商品: List<Product> hList = productService.findByHot(); // 查询最新商品: List<Product> nList = productService.findByNew(); // 存入到值栈: // 获得值栈: ValueStack stack = ActionContext.getContext().getValueStack(); // stack.set("cList", cList); ActionContext.getContext().getSession().put("cList", cList); stack.set("hList", hList); stack.set("nList", nList); return "index"; }
时间: 2024-10-10 18:09:47