Prerequisite: java
, springmvc
.
I have a service class of userService
, which contains 2
methods to operate the current user, getCurrenUser
and setCurrenUser
.
But these two methods either obtain token
from request
, or read information from session
.
The leader told me that the service
layer should not write request
related code,
Is this reasonable?
I personally believe that the service
layer should only focus on logic and should not be strongly dependent on certain environments. but. . . Where should I write a class that operates CurrenUser
?
From your description, it seems that you want to use the request object in the Service layer to obtain the user information in the session.
I remember that the Spring framework can register a RequestContextListener, and then you can get the request through RequestContextHolder without passing it to the Service through the Controller. I seem to have used AOP in previous projects, but I can’t remember the details.
Also, I think, writing code depends on your mood, you can write how you want. :-)
I don’t know what you mean.
Just add a new one in the controller method.
Yes, according to the post with the accepted answer, Baidu has published relevant articles.
http://blog.csdn.net/jiaobuch...
http://blog.csdn.net/u0127068...