当前位置:   article > 正文

SpringBoot-项目3-商品(首页,详情页)_springboot3实现商品和sku的添加

springboot3实现商品和sku的添加

创建商品表及商品分类表

# 商品表
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
# 商品分类表
分类表(id,title,image,desc,isdelete,created_user,created_time,modified_user,modified_time)
  • 1
  • 2

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等方法
  
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

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

(a) 规划需要的SQL语句

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

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

(b) 设计抽象方法

cn.demo.store.mapper包下创建ProductMapper 接口,并添加抽象方法:

/**
 * 处理商品数据的持久层接口
 */
public interface ProductMapper {
   
  
  /**
   * 查询热销商品排行的前4个商品
   * @return 热销商品排行的前4个商品
   */
  List<Product> findHotList();

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

© 配置映射并测试

src/main/resources/mappers下创建ProductMapper.xml,用于配置以上抽象方法的映射:

<mapper namespace="cn.demo.store.mapper.ProductMapper">

  <resultMap type="cn.demo.store.entity.Product" id="ProductEntityMap">
    <id column
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/355623
推荐阅读
相关标签
  

闽ICP备14008679号