MyBatis Plus 查询 ymd 字段当月记录
你可以使用 MyBatis Plus 的 Wrapper 类来查询 ymd 字段在当月的记录,如下所示:
// 创建Wrapper对象
QueryWrapper<Entity> wrapper = new QueryWrapper<>();
// 在wrapper中设置查询条件,ymd字段在当月
wrapper.apply("date_format(ymd,'%Y-%m') = date_format(now(),'%Y-%m')");
// 调用selectList方法执行查询
List<Entity> list = entityMapper.selectList(wrapper);
上述代码中,我们通过 QueryWrapper 的 apply 方法设置查询条件,利用 MySQL 的 date_format 函数将 ymd 字段的年月与当前年月进行比较,从而查询 ymd 字段在当月的记录。
注意:上述代码中的 Entity 是你自定义的实体类,entityMapper 是对应的 Mapper 接口。
原文地址: https://www.cveoy.top/t/topic/mGWa 著作权归作者所有。请勿转载和采集!