ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletResponse response = attrs.getResponse(); HttpServletRequest request = attrs.getRequest();…
通过  System.Web.HttpContext.Current  获取 public static string ConstractExportExcel(List<ERP_Contract> list, string FilePath) { //获取Response HttpResponse Response = System.Web.HttpContext.Current.Response; }…
一般我们在Controller层,会编写类似这样的方法 @Controller @RequestMapping(value="/detail") public class GetURIDetailController { @SystemControllerLog(description = "id") @RequestMapping(value="/{id}",method={RequestMethod.GET}) public ModelAnd…
RequestContextListener实现了 ServletRequestListener ,在其覆盖的requestInitialized(ServletRequestEvent requestEvent)方法中,将request最终设置到了RequestContextHolder中. public class RequestContextListener implements ServletRequestListener { private static final String RE…
<code class=" hljs java">package gacl.response.study; 2 3 import java.io.IOException; 4 import java.io.OutputStream; 5 import javax.servlet.ServletException; 6 import javax.servlet.http.HttpServlet; 7 import javax.servlet.http.HttpServletR…
最近,为了解耦,把一逻辑从interceptor抽出来,放在aop中处理,需要得到RequestBody.如下: @Aspect @Configuration public class CheckAspect { private final Logger logger = LoggerFactory.getLogger(this.getClass()); // 定义切点Pointcut 自行写入对应的controller包路径 @Pointcut("execution(* com.hs.yido…
首先要在web.xml增加如下代码: <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class></listener> service层调用 @Autowired private HttpSession session; @Autowired private HttpServletRequest reque…
方法一:request.getParameter("name") 方法二:注解@RequestParam @RequestMapping("testRequestParam") //注解的方式 public String filesUpload(@RequestParam(value="inputStr", required=false) String inputStr, HttpServletRequest request) { System.…
今天在使用swagger2测试的时候出错 1.@requestBody注解常用来处理content-type不是默认的application/x-www-form-urlcoded编码的内容,比如说:application/json或者是application/xml等.一般情况下来说常用其来处理application/json类型. 2. 通过@requestBody可以将请求体中的JSON字符串绑定到相应的bean上,当然,也可以将其分别绑定到对应的字符串上. 例如说以下情况: $.ajax…
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml"); pushMessageService = (PushMessageService)ctx.getBean(PushMessageService.class); List<PushMessage> pmList = pushMessageService.getPushMessageById(userId);…