您好,我有一个代码,我想将我的集合公开为 JSON 格式。我以为Spring会自动完成它。这是代码:
@RestController
public class BirthdayController extends BaseController{
@RequestMapping("/api/v1/birthday")
public TreeMap<Integer, TreeMap<Integer, ArrayList<BirthdayDetails>>> getBirthdays(@RequestParam(value="startYear") Integer startYear,
@RequestParam(value="startMonth") Integer startMonth,
@RequestParam(value="endYear") Integer endMonth,
@RequestParam(value="endMonth") Integer endYear) {
BirthdayServiceImpl birthdayService = new BirthdayServiceImpl();
return birthdayService.getBirthdaysBetweenDate(startMonth, startYear, endMonth, endYear);
}
}
访问端点时我只得到空的 {}
最佳答案
尝试,
@RequestMapping("/api/v1/birthday")
public @ResponseBody TreeMap<Integer, TreeMap<Integer, ArrayList<BirthdayDetails>>> getBirthdays(@RequestParam(value="startYear") Integer startYear,
@RequestParam(value="startMonth") Integer startMonth,
@RequestParam(value="endYear") Integer endMonth,
@RequestParam(value="endMonth") Integer endYear) {
BirthdayServiceImpl birthdayService = new BirthdayServiceImpl();
return birthdayService.getBirthdaysBetweenDate(startMonth, startYear, endMonth, endYear);
}
关于java - 如何将包含内容的 TreeMap 转换为 JSON 格式 Spring REST Controller JAVA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40465118/