java - Include login methods -


i got entity user , want every method of every controller have access logged user without typing :

model.addattribute(userdao.getuser(principal.getusername())); 

you can implement simple handlerinterceptoradapter add user instance model after handler invoked.

class useraddinghandlerinterceptor extends handlerinterceptoradapter {      // autowire dependencies...      private static final string attribute = "user";      @override     public void posthandle(httpservletrequest request,                             httpservletresponse response,                             object handler,                             modelandview modelandview) throws exception {          if (modelandview != null && !modelandview.getmodelmap().hasattribute(attribute) {             modelandview.addobject(attribute, userdao.getuser(principal.getusername()));         }     } } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -