java - Should the service layer not write http-related operations?
给我你的怀抱
给我你的怀抱 2017-06-23 09:14:01
0
3
1025

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?

给我你的怀抱
给我你的怀抱

reply all(3)
过去多啦不再A梦

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...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template