1、调用后端接口时,返回最大页码数,这样就可以避免
// 最后一页就剩一条,删除或者取消关注,默认展示前一页 if (tableData?.length == 0 && currentPage > 1) { const beforePageNum = result?.maxPage == 0 ? 1 : result?.maxPage; setCurrentPage(beforePageNum); }
2、计算两个日期的间隔天数
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.Objects; public static Long getPeriodDays(Date beforeDate, Date afterDate) { if (afterDate == null || beforeDate == null) { return null; } SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String beforeDateStr = format.format(beforeDate); String afterDateStr = format.format(afterDate); LocalDate beforeDateLocal = LocalDate.parse(beforeDateStr, formatter); LocalDate afterDateLocal = LocalDate.parse(afterDateStr, formatter); Long period = ChronoUnit.DAYS.between(beforeDateLocal, afterDateLocal); return period; }
标签:java,format,LocalDate,最后,text,一页,import,数据 From: https://www.cnblogs.com/Small-sunshine/p/17916477.html