Mybatis-Plus time and date comparison
When obtaining records in the database that are equal to the current date
Or call the eq method, so the entity class includes the type Date, not DateTime, otherwise it can only get data at the same time.
pulbic void main(){ LocalDate now = (); LambdaQueryWrapper<Ebbinghaus> queryWrapper = new LambdaQueryWrapper(); (,now); (queryWrapper); }
Mybatis-Plus time comparison is based on database functions, not string comparisons.
In Mybatis-Plus, you can use the Wrapper object'sge、gt、le、lt
Method to compare time.
These methods will generate corresponding SQL statements according to the different databases to implement time comparison operations.
So, there is no need to convert time to string for comparison.
If you want to compare the number of days, it is best to use LocalDate as the type of data instead of LocalDateTime, otherwise the comparison is only greater than the current moment, greater than or equal to the current moment.
If there is an operational requirement for the time value of the data
The following settings can be made:
@JsonFormat(pattern = "yyyy-MM-dd") private LocalDateTime createTime;
The corresponding field type in the database is set to date, not datetime, so that the number of days can be compared and there are more abundant operations at the moment.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.