1. 程式人生 > 實用技巧 >mybatis-plus解決時間範圍查詢同一天bug

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; } }

效果: