V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
aoscici2000
V2EX  ›  Java

spring 中 拦截器 是否可以把数据传给 handler

  •  
  •   aoscici2000 · Oct 12, 2019 · 3399 views
    This topic created in 2394 days ago, the information mentioned may be changed or developed.
    public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) {
        Map<String, Object> data = .....;
        return true;
    }
    
    @RequestMapping(value = "/user/{uid}", method = RequestMethod.PUT)
    public JsonResult updateById(@PathVariable Integer uid) {
        这里能否用到 data ?
        return userService.updateById(uid);
    }
    

    如题, 在拦截器里产生的数据, 能否传给 handler

    2 replies    2019-10-12 08:26:13 +08:00
    DonaldY
        1
    DonaldY  
       Oct 12, 2019
    可以, 通过 requestmap
    `this.setRequestAttribute(req, "", "");`
    `@RequestAttribute`
    wenzhoou
        2
    wenzhoou  
       Oct 12, 2019 via Android
    还可以用 thread local
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2112 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:33 · PVG 08:33 · LAX 17:33 · JFK 20:33
    ♥ Do have faith in what you're doing.