HttpEntity
@ResponseBody //@ResponseBody:是将内容或对象作为Http响应正文返回 @RequestMapping(“/testHttpMessageConverter”) //@RequestBody:是将Http请求正文插入方法中,修饰目标方法的入参 public String testHttpMessageConverter(@RequestBody String body){ System.out.println(“body=”+body); return “Hello,” + new Date(); //不再查找跳转的页面 } |
/files/abc.txt 准备一个下载的文件 |
@RequestMapping(“testResponseEntity”) public ResponseEntity ServletContext servletContext = session.getServletContext(); InputStream resourceAsStream = servletContext.getResourceAsStream(“/files/abc.txt”); byte[] body = new byte[resourceAsStream.available()] ; resourceAsStream.read(body); MultiValueMap headers.add(“Content-Disposition“, “attachment;filename=abc.txt”); HttpStatus statusCode = HttpStatus.OK; ResponseEntity return responseEntity ; } |
想要了解跟多关于java培训课程内容欢迎关注尚硅谷java培训,尚硅谷除了这些技术文章外还有免费的高质量java培训课程视频供广大学员下载学习。