web项目中从request取值

request取值

在javaweb项目中,很多时候我们都要从request中取值。一般我们都是这样

1
2
3
4
@PostMapping("/test")
public String test(HttpServletRequest request){
request.getParameter("");
}

但是有时我们在使用一些其他框架时,在参数中不能添加HttpServletRequest,此时可以换一种方法获取request

1
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

这样在web项目中的任何地方都能获取request

相关文章
评论
分享
Please check the post_relate setting in config.yml of hexo-theme-Annie! You should make sure 'postsEnable == true' and the number of site posts greater than 1.
Please check the comment setting in config.yml of hexo-theme-Annie!