在Springboot上下文中获取HttpServletRequest和HttpServletResponse


HttpServletRequest request =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse response =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();


一般使用

HttpServletRequest request =((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();

HttpServletResponse response =((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getResponse();

上一篇:速战速决 go - go 面向对象: 函数(函数也是一种类型,匿名函数,闭包)


下一篇:对GO切片的理解