SpringBoot构建电商基础秒杀项目-----学习笔记5

本文档记录了使用SpringBoot构建电商基础秒杀项目的交易模块实现过程,包括OrderModel的设计,mybatis-generator配置,OrderService与OrderServiceImpl的创建,以及ItemStockDOMapper和ItemDOMapper中库存与销量的更新方法。通过减少SQL执行次数来优化库存操作,同时介绍了SequenceDOMapper获取序列的方法,用于订单编号生成。最后提到了交易模块的简单总结,涉及库存与商品表的设计决策和下单流程中的库存管理策略。
摘要由CSDN通过智能技术生成

交易模块的实现

创建模型 OrderModel

@Data
public class OrderModel {
    private String id;
    private Integer userId;
    private Integer itemId;
    private BigDecimal itemPrice;
    private Integer amount;
    private BigDecimal orderPrice;
}

mybatis-generator.xml 添加下列代码,生成DO类

 <table  tableName="order_info" domainObjectName="OrderDO"
                enableCountByExample="false" enableUpdateByExample="false"
                enableDeleteByExample="false" enableSelectByExample="false"
                selectByExampleQueryId="false">
</table>

<table tableName="sequence_info" domainObjectName="SequenceDO"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
</table>

创建 OrderService、OrderServiceImpl

public interface OrderService {
    // 创建订单
    OrderModel createOrder(Integer userId, Integer itemId, Integer promoId, Integer amount) throws BusinessException;
}
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private ItemService itemService;

    @Autowired
    private UserService userService;

    @Autowired
    private OrderDOMapper orderDOMapper;

    @Autowired
    private Sequen
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值