Comments (3)
你好,原理是:通过自定义拦截器,拦截方法;然后根据请求方法中携带的cookie从redis中获取用户信息,就为UserVo。
实现参考:
(1)拦截器accessInterceptor和userArgumentResolver注册代码在:dis-seckill-gateway\src\main\java\com\seckill\dis\gateway\config\WebConfig.java中。
(2)AccessInterceptor:dis-seckill-gateway\src\main\java\com\seckill\dis\gateway\config\access\AccessInterceptor.java中,
preHandle里面的getUser方法,可以根据cookie获取用户信息,然后保存在ThreadLocal中。
(3)userArgumentResolver:dis-seckill-gateway\src\main\java\com\seckill\dis\gateway\user\UserController.java中,
resolveArgument方法通过getUser方法从ThreadLocal中获取用户信息,然后自动解析为方法中UserVo参数。
from dis-seckill.
你好,原理是:通过自定义拦截器,拦截方法;然后根据请求方法中携带的cookie从redis中获取用户信息,就为UserVo。 实现参考: (1)拦截器accessInterceptor和userArgumentResolver注册代码在:dis-seckill-gateway\src\main\java\com\seckill\dis\gateway\config\WebConfig.java中。 (2)AccessInterceptor:dis-seckill-gateway\src\main\java\com\seckill\dis\gateway\config\access\AccessInterceptor.java中, preHandle里面的getUser方法,可以根据cookie获取用户信息,然后保存在ThreadLocal中。 (3)userArgumentResolver:dis-seckill-gateway\src\main\java\com\seckill\dis\gateway\user\UserController.java中, resolveArgument方法通过getUser方法从ThreadLocal中获取用户信息,然后自动解析为方法中UserVo参数。
非常感谢及时的解答,我还有一个小问题
OrderController 中
public Result orderInfo(Model model, UserVo user, @RequestParam("orderId") long orderId)
这里的model参数又是从哪里来的呢
from dis-seckill.
你好,在这个函数里面,model是没有用到的参数,可以去掉。
当前端用到Thymeleaf 模板时,Model 对象负责在控制器和展现数据的视图之间传递数据。参考知识:https://www.cnblogs.com/youcoding/p/13763621.html。
项目中代码事例:templates/goods_detail.html和goods/GoodsController.java
from dis-seckill.
Related Issues (6)
- 很不错的项目,感谢分享 HOT 2
- 我在windows下按序启动,前五个没问题,最后启动网关报错 HOT 2
- 在分布式的情况下,该系统是否需要分布式事务组件来保证最终一致性?还是系统中已经保证了 HOT 2
- 两次md5 HOT 1
- 启动报错 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dis-seckill.