在做黑马点评项目时,p51章使用下面这段代码做查询,在高并发环境下存在bug,按理说库存会减到负数,而我的库存有几十个
boolean update = iSeckillVoucherService.lambdaUpdate()
.set(SeckillVoucher::getStock, one.getStock() - 1)
.eq(SeckillVoucher::getVoucherId, one.getVoucherId())
.update();
对应控制台发送的sql语句是
Preparing: UPDATE tb_seckill_voucher SET stock=? WHERE (voucher_id = ?)
2023-06-22 22:21:55.214 DEBUG 15568 --- [ main] c.h.mapper.SeckillVoucherMapper.update : ==> Parameters: 99(Integer), 7(Long)
2023-06-22 22:21:55.215 DEBUG 15568 --- [ main] c.h.mapper.SeckillVoucherMapper.update : <== Updates: 1
使用第二种手写sql时代码和控制台发送的语句如下
boolean result = iSeckillVoucherService.lambdaUpdate()
.setSql("stock = stock - 1")
.eq(SeckillVoucher::getV