mybatis-plus解決時間范圍查詢同一天bug


/**
 * 參數類
 */
@Data
public class T {
    private String startDate;
    private String endDate;
}
/**
 * test
 *實體類
 * @author
 */
@Data
@TableName("test")
public class Test implements Serializable {
    @TableId("id")
    private Integer id;
    @TableField("date")
    //出參
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "GMT+8")
    //入參
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date date;

    private static final long serialVersionUID = 1L;
}
import java.util.List;

@Service
@Slf4j
public class TestService {
    @Autowired
    private TestDao testDao;

    public List<Test> getT(T t) {
        LambdaQueryWrapper<Test> te = new LambdaQueryWrapper<Test>();
        String startDate = t.getStartDate();
        String endDate = t.getEndDate();
        te.ge(Test::getDate, startDate).apply("DATE_FORMAT(date,'%Y-%m-%d') <= DATE_FORMAT({0},'%Y-%m-%d')", endDate);
        List<Test> tests = testDao.selectList(te);
        return tests;
    }

}

效果:

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM