赞
踩
# 商品表 CREATE TABLE `t_product` ( `id` int(20) NOT NULL COMMENT '商品id', `category_id` int(20) DEFAULT NULL COMMENT '分类id', `item_type` varchar(100) DEFAULT NULL COMMENT '商品系列', `title` varchar(100) DEFAULT NULL COMMENT '商品标题', `sell_point` varchar(150) DEFAULT NULL COMMENT '商品卖点', `price` bigint(20) DEFAULT NULL COMMENT '商品单价', `num` int(10) DEFAULT NULL COMMENT '库存数量', `image` varchar(500) DEFAULT NULL COMMENT '图片路径', `status` int(1) DEFAULT 1 COMMENT '商品状态 1:上架 2:下架 3:删除', `priority` int(10) DEFAULT NULL COMMENT '显示优先级', `created_time` datetime DEFAULT NULL COMMENT '创建时间', `modified_time` datetime DEFAULT NULL COMMENT '最后修改时间', `created_user` varchar(50) DEFAULT NULL COMMENT '创建人', `modified_user` varchar(50) DEFAULT NULL COMMENT '最后修改人', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
# 商品分类表
分类表(id,title,image,desc,isdelete,created_user,created_time,modified_user,modified_time)
当前项目中的登录拦截器默认是拦截/**
路径 ,则所有请求路径默认都需要登录,而主页、商品详情等页面应该不需要登录就可以访问,所以,需要将/web/index.html
、/web/product.html
添加到配置拦截器的白名单中!
在cn.demo.store.entity
包中创建Product
实体类:
/** * 商品数据的实体类 */ public class Product extends BaseEntity { private static final long serialVersionUID = 6884621327188442341L; private Integer id; private Integer categoryId; private String itemType; private String title; private String sellPoint; private Long price; private Integer num; private String image; private Integer status; private Integer priority; // 生成get/set方法,toString()方法,hashCode/equals等方法 }
查询热销排行商品的SQL语句是(此页面热销商品只显示4个):
select * from t_product where status=1 order by priority desc limit 0,4
在cn.demo.store.mapper
包下创建ProductMapper
接口,并添加抽象方法:
/**
* 处理商品数据的持久层接口
*/
public interface ProductMapper {
/**
* 查询热销商品排行的前4个商品
* @return 热销商品排行的前4个商品
*/
List<Product> findHotList();
}
在src/main/resources/mappers下创建ProductMapper.xml,用于配置以上抽象方法的映射:
<mapper namespace="cn.demo.store.mapper.ProductMapper">
<resultMap type="cn.demo.store.entity.Product" id="ProductEntityMap">
<id column
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。