Mybatis plus 使用andNew将条件查询用括号分割(转载其他大咖的博客)

//有很多中Wrapper实现类,我也不是很了解,这里我使用的是EntityWrapper
 EntityWrapper wrapper = new EntityWrapper();
 wrapper.eq("status", status);
 wrapper.andNew().gt("gmt_end", now).or().isNotNull("days");
 Integer count = couponMapper.selectCount(wrapper);

生产的原生sql语句结果如下:

SELECT COUNT(1) FROM unimall_coupon WHERE (status = 1) AND (gmt_end > '2019-07-14 16:14:23.51' OR days IS NOT NULL)

很明显andNew的作用就是 在 新 and 条件后整体加了一个新( ) 条件的限制 

猜你喜欢

转载自blog.csdn.net/zy103118/article/details/107560337