文章目录 背景 方法一 使用@ResponseBody注解 方法二 使用标准的返回值ModelAndView 方法三 使用流返回 背景 在前端请求数据需要进行ajax异步请求,需要获取JSON格式的数据 方法一 使用@ResponseBody注解 但有些时候使用不了这个注解 @ResponseBody public HashMap<String,String> modelTest(HttpServletRequest request, HttpServletResponse response){ HashMap<String, String> hashMap = new HashMap<>()