(1)springboot注解,当接收页面单个:参数字符串数组。必须加 org.springframework.web.bind.annotation.RequestBody 注解, 如果是整形数组,则换成 Integer[] ids 即可。
@PostMapping("/demo")
@ResponseBody
public Result test(@RequestBody Long[] ids) {
}
(2)获取最近12个月份
public List<String> get12Month() {标签:知识点,set,java,get,dateList,MONTH,Calendar,calendar From: https://www.cnblogs.com/wmqxlt/p/18056069
List<String> dateList = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
// 月份最大为11 最小为0 所以设置初始月份时加1,需要获取到当前月份所以设置初始月份时需要加2
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + 2);
calendar.set(Calendar.DAY_OF_MONTH, 1);
for (int i = 0; i < 12; i++) {
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
//此处需要设置日期,否则默认取31号,但是二月份没有31号
calendar.set(Calendar.DAY_OF_MONTH, 1);
// 需要判断月份是否为0 如果0则需要转换成12,年份转为去年;,如果月份小于10,则前面加上0
dateList.add(calendar.get(Calendar.MONTH) == 0 ? calendar.get(Calendar.YEAR) - 1 + "-" + 12 : calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) < 10 ? "0" + calendar.get(Calendar.MONTH) : calendar.get(Calendar.MONTH)));
}
dateList = dateList.stream().sorted().collect(Collectors.toList());
return dateList;
}