My table is able to get data from the past 3 months if I select them individually (For example, click March 2020 and it will display data from 2020).
But if I want it to display whole full 3 months of the data onto the table (For example, click "ALL" and it will display data from March, April and May).
What kind of logic or code should I add onto the SearchMonth.java in order to make it able to display it?
SearchMonth.java
import java.util.Calendar;
import java.util.Date;
package com.enums;
public enum SearchMonthPeriod {
ALL("All", "All (Default)"),
ONE("1", "A month Ago"),
TWO("2", "Two months Ago"),
THREE("3", "Three months Ago");
SearchMonth(String code, String label) {
this.code = code;
this.label = label;
}
private String code;
private String label;
private static String[] months = {"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"};
public String getCode() {
return code;
}
public String getLabel() {
return label;
}
public static String[] getMonths() {
return months;
}
}
controller.java
private List<String> createMonthSearchOption() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
int mon = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
List<String> monthList = Arrays.asList(SearchMonthPeriod.getMonths());
List<String> searchOption = new ArrayList<String>();
// Last 3 months
for (int a = 0; a < 3; a++) {
searchOption.add(monthList.get(mon) + " " + String.valueOf(year));
mon--; // Go to previous month
// Reset if reach the first element
if (mon == -1) {
mon = 11;
year--;
}
}
return searchOption;
}
html code (shortened)
<select id="month" th:field="*{month}"
class="browser-default custom-select">
<option
th:value="${T(com.cv.p2p.sc.enums.SearchMonth).ALL}"
th:text="All (Default)"></option>
<option
th:value="${T(com.cv.p2p.sc.enums.SearchMonth).ONE}"
th:text="${searchOption[0]}"></option>
<option
th:value="${T(com.cv.p2p.sc.enums.SearchMonth).TWO}"
th:text="${searchOption[1]}"></option>
<option
th:value="${T(com.cv.p2p.sc.enums.SearchMonth).THREE}"
th:text="${searchOption[2]}"></option>
</select>
question from:
https://stackoverflow.com/questions/65950669/how-to-get-all-dates-gathered-throughout-the-whole-3-months-and-display-using-th 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…