spring mvc获取header
作者:互联网
两种方法:
1.在方法参数中加入@RequestHeader
2.在类级别注入HttpServletRequest
建议使用第二种方法,这样可避免每个方法都加入HttpHeaders参数
- @Controller
- @RequestMapping("/hello")
- public class HelloController {
- @Autowired
- private HttpServletRequest request;
- @RequestMapping(value="/printname/{name}", method=RequestMethod.GET)
- public String printName(@PathVariable String name,
- @RequestHeader HttpHeaders headers) {
- System.out.println("from request:" + request.getHeader("code"));
- System.out.println("from parameter:" + headers.getFirst("code"));
- return "hello";
- }
- }
https://www.iteye.com/blog/flysnowxf-1187567
标签:code,String,RequestHeader,spring,request,System,header,mvc,out 来源: https://www.cnblogs.com/myfrank/p/11621784.html