如何在Springboot中将拦截器添加到一个特定的URL中?
我有一个如下:
@RestController
@RequestMapping("/user")
public class UserController {
@Resource
UserService userService;
@PostMapping("/create")
public Map<String, Object> createAccount(User user) {
return userService.createAccount(user);
}
@PostMapping("/login")
public Map<String, Object> accountLogin(User user) {
return userService.accountLogin(user);
}
@GetMapping("/activate")
public Map<String, Object> activateAccount(String confirmationCode) {
return userService.activateAccount(confirmationCode);
}
@PostMapping("/roleChange")
public Map<String, Object> setUserRole(String uuid, String email, String roleId){
return userService.setUserRole(uuid, email, roleId);
}
}
现在,我想仅将interceptor添加到/user/rolechange
。我知道您可以使用.excludepathpatterns()
来排除所有其他路径,但是我很好奇是否有办法为Interpector指定一条路径。谢谢你!
I have a UserController class as below:
@RestController
@RequestMapping("/user")
public class UserController {
@Resource
UserService userService;
@PostMapping("/create")
public Map<String, Object> createAccount(User user) {
return userService.createAccount(user);
}
@PostMapping("/login")
public Map<String, Object> accountLogin(User user) {
return userService.accountLogin(user);
}
@GetMapping("/activate")
public Map<String, Object> activateAccount(String confirmationCode) {
return userService.activateAccount(confirmationCode);
}
@PostMapping("/roleChange")
public Map<String, Object> setUserRole(String uuid, String email, String roleId){
return userService.setUserRole(uuid, email, roleId);
}
}
Now I wanna add an interceptor to /user/roleChange
only. I know you can exclude all the other paths with .excludePathPatterns()
but I'm just curious if there's a way to specify one path for the interceptor. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是Interceptor的示例代码,
在此中,我有“拦截器”注册“/用户”。
Below is the sample code for interceptor
In this I have register "/user" for interceptor.