mybatisplus 查询当月数据
时间: 2023-09-20 07:07:28 浏览: 48
使用 MybatisPlus 进行当前月份的数据查询可以使用如下的方式:
```java
// 获取当前月份的起始时间和结束时间
LocalDate now = LocalDate.now();
LocalDate firstDayOfMonth = now.with(TemporalAdjusters.firstDayOfMonth());
LocalDate lastDayOfMonth = now.with(TemporalAdjusters.lastDayOfMonth());
LocalDateTime startOfMonth = LocalDateTime.of(firstDayOfMonth, LocalTime.MIN);
LocalDateTime endOfMonth = LocalDateTime.of(lastDayOfMonth, LocalTime.MAX);
// 构造查询条件
QueryWrapper<Entity> queryWrapper = new QueryWrapper<>();
queryWrapper.between("create_time", startOfMonth, endOfMonth);
// 执行查询
List<Entity> result = entityMapper.selectList(queryWrapper);
```
其中,`Entity` 表示需要查询的实体类,`entityMapper` 表示该实体类对应的 MybatisPlus Mapper 接口。在查询条件中,使用 `between` 方法设置查询时间段,实现筛选出当前月份的数据。