Springmvc @responseBody返回json,弹出下载

新手上路,请多包涵

@RequestMapping(value = "/getMgInsurancesByParams.do",produces="application/json;charset=UTF-8")

@ResponseBody
public String getMgInsurancesByParams() {
return "abc";
}
![图片描述][1]
阅读 5.7k
2 个回答

设置header
Content-Disposition: attachment; filename=下载文件名

直接上代码了。

@RequestMapping(value = "/test4")
public
@ResponseBody
String downLoad(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    httpServletResponse.setContentType("application/json");
    httpServletResponse.setHeader("Content-disposition", "attachment; filename=" + "测试json数据");
    return "66";
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题