Spring: how to pass objects from filters to controllers

前端 未结 5 1404
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 05:19

I\'m trying to add a Filter that creates an object that is then to be used inside a controller in a Spring Boot application.

The idea is to use the Filter as a \"cen

5条回答
  •  误落风尘
    2021-01-02 05:45

    An addition to wcong's answer. Since Spring 4.3 after setting the attribute by using request.setAttribute(passKey, passValue);, you can access the attribute in your controller by simply annotating it with @RequestAttribute.

    ex.

    @RequestMapping("/")
    public String index(@RequestAttribute passKey) {
        return (String) passKey;
    }
    

提交回复
热议问题