search

Home  >  Q&A  >  body text

java - Should the service layer not write http-related operations?

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?

给我你的怀抱给我你的怀抱2771 days ago1042

reply all(3)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-23 09:16:01

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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-23 09:16:01

    I don’t know what you mean.
    Just add a new one in the controller method.

    reply
    0
  • 黄舟

    黄舟2017-06-23 09:16:01

    Yes, according to the post with the accepted answer, Baidu has published relevant articles.

    http://blog.csdn.net/jiaobuch...

    http://blog.csdn.net/u0127068...

    reply
    0
  • Cancelreply