我可以在任何@RestController
中爲任何@RequestMapping
方法添加過濾器嗎?如何在Spring servlet的所有@RequestMapping方法上添加一個過濾器?
我希望該過濾器適用於映射對象。因此,在之後該請求已被映射到DTO,但之前@RequestMapping
方法執行。
這可能嗎?
@RestController
public class MyServlet {
@RequestMapping(method = GET)
public void get(GetDTO dto) {
}
@RequestMapping(method = POST)
public void get(PostDTO dto) {
}
}
https://stackoverflow.com/questions/35198604/how-to-register-a-filter-to-one-requestmapping-method-only – sForSujit
不。我的問題是如何添加一個截取到dto映射和調用'@ RequestMapping'映射的過濾器。您的鏈接問題是關於如何將過濾器添加到**特定**'@ RequestMapping'。 – membersound
您可以使用'HandlerInterceptor' – Zico