java - If I have a handler interceptor that loads a user object, adds it to request attri, do I cast to get object? -


I am planning to create a handler interceptor that will set the fire to the controller before calling (or I will do this pre-action Firing).

I will then check the user's cookie and load the user object based on the session's session.

I will then add the user's object to the request attributes.

Now if I want to retrieve the user object in my controller action, then have I put it in user (user)?

I believe that I can only $ $ users in my freemarker template. Name} is correct? Or is this user.getUsername?

First of all, you will give the user a better location in the session, because the cookie> users on each request The conversion does not happen.

Second, you can get it (session / request) by calling

  user user = (user) session.getAttribute (USER_KEY); // This string is stable  

Alternatively, you can create a class UserHolder , where you pass a HttpSession And this gives you the user, thus your controller is put in the cot.

Use the same approach as HttpServletRequest .

.

Comments