当前位置:网站首页>通过实现参数解析器HandlerMethodArgumentResolver接口来自定义注解
通过实现参数解析器HandlerMethodArgumentResolver接口来自定义注解
2022-04-23 07:16:00 【hungry&foolish】
HandlerMethodArgumentResolver类似于拦截器,是一个参数解析器,我们可以通过写一个类实现HandlerMethodArgumentResolver接口来实现对Controller层中方法参数的修改
自定义解析器需要实现HandlerMethodArgumentResolver接口,HandlerMethodArgumentResolver接口包含两个接口函数:

当supportsParameter返回True时,才会调用resolveArgument。
实例:
声明自定义的注解(用于获取用户的userid)

写一个LoginUserHandlerMethodArgumentResolver类实现HandlerMethodArgumentResolver接口

在resolveArgument中会获取token,然后根据token获取userid并返回
版权声明
本文为[hungry&foolish]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_35227352/article/details/124302257
边栏推荐
猜你喜欢
随机推荐
单点登录 SSO
【Appium】测试时遇到手机内嵌H5页面的切换问题
The following program deletes n consecutive words starting from the ith character from the string str
网赚APP资源下载类网站源码
Jetson Xavier NX(3)Bazel Mediapipe 安装
LeetCoed18. Sum of four numbers
LeetCode简单题之统计字符串中的元音子字符串
AAAI 2022招募讲者啦!!
Install MySQL for Ubuntu and query the average score
Kubernetes in browser and IDE | interactive learning platform killercoda
Mobile terminal layout (3D conversion, animation)
3C装配中的机械臂运动规划
华硕笔记本电脑重装系统后不能读取usb,不能上网
The third divisor of leetcode simple question
Discussion on ES6 tail tune optimization
Compiler des questions de principe - avec des réponses
js常用数组方法
Qt编译QtXlsx库
[untitled]
Distributed service governance Nacos









