SpringBoot-项目3-商品(首页,详情页)

创建商品表及商品分类表

# 商品表
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)

54. 将商品相关页面添加到拦截器白名单

当前项目中的登录拦截器默认是拦截/**路径 ,则所有请求路径默认都需要登录,而主页、商品详情等页面应该不需要登录就可以访问,所以,需要将/web/index.html/web/product.html添加到配置拦截器的白名单中!

55. 创建商品数据的实体类

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等方法
  
}

56. 主页-热销排行-持久层

(a) 规划需要的SQL语句

查询热销排行商品的SQL语句是(此页面热销商品只显示4个):

select * from t_product where status=1 order by priority desc limit 0,4

(b) 设计抽象方法

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
  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值