Mybatis-Plus时间查询
public List<HroAttendanceStatistics> listEffectiveByWorkNo(String workNo) {
LambdaQueryWrapper<HroAttendanceStatistics> queryWrapper = new QueryWrapper<HroAttendanceStatistics>().lambda();
queryWrapper.eq(HroAttendanceStatistics::getWorkerNo, workNo);
queryWrapper.eq(HroAttendanceStatistics::getDeleted, 0);
queryWrapper.eq(HroAttendanceStatistics::getEffective, EffectiveStatusEnum.TAKE_EFFECT.getCode());
queryWrapper.eq(HroAttendanceStatistics::getApplicationStatus, DocumentStatusEnum.AGREE.getCode());
// 这行代码是查询创建时间大于等于60天前的记录。
queryWrapper.ge(HroAttendanceStatistics::getTCreated, LocalDateTime.now().minusDays(60));
//查询创建时间小于等于当前时间的记录。
queryWrapper.le(HroAttendanceStatistics::getTCreated, LocalDateTime.now());
queryWrapper.orderByDesc(HroAttendanceStatistics::getTCreated);
return hroAttendanceStatisticsMapper.selectList(queryWrapper);
}
其中:
1,ge 表示 “greater than or equal”(大于等于)
LocalDateTime.now().minusDays(60) 计算60天前的时间点
整体相当于 SQL:WHERE t_created >= (CURRENT_TIMESTAMP - INTERVAL ‘60’ DAY)
2,le 表示 “less than or equal”(小于等于)
HroAttendanceStatistics::getTCreated 是指向 HroAttendanceStatistics 类的 tCreated 字段
LocalDateTime.now() 获取当前时间
整体相当于 SQL 中的:WHERE t_created <= NOW()
MyBatis-Plus 的比较运算符:
gt: 大于 (>)
ge: 大于等于 (>=)
lt: 小于 (<)
le: 小于等于 (<=)
eq: 等于 (=)