V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
aoscici2000
V2EX  ›  Java

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

  •  
  •   aoscici2000 · 2019-10-12 01:38:45 +08:00 · 2678 次点击
    这是一个创建于 1629 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2019-10-12 08:26:13 +08:00
    DonaldY
        1
    DonaldY  
       2019-10-12 02:40:16 +08:00
    可以, 通过 requestmap
    `this.setRequestAttribute(req, "", "");`
    `@RequestAttribute`
    wenzhoou
        2
    wenzhoou  
       2019-10-12 08:26:13 +08:00 via Android
    还可以用 thread local
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1570 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:00 · PVG 01:00 · LAX 10:00 · JFK 13:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.