Java后端获取前端传过来header中的值

Java后端获取前端传过来header中的值
比如获取前端传值token值:
方法一:不需要在参数中写HttpServletRequest request

ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request1 = attributes.getRequest();
String token=request1.getHeader("token");

方法二:需要在参数中写HttpServletRequest request

String token = request.getHeader("token");

你可能感兴趣的:(编程小问题,前端,后端,java)