Normally, we'll write a method like this in the controller layer.
@Controller
@RequestMapping (value= "/detail")
Public class Geturidetailcontroller {
@SystemControllerLog (description = "id" ) @RequestMapping (value = "/{id}", Method={requestmethod.get}) public Modelandview Getdetailid (@PathVariable (" id ", httpservletrequest request) {Modelandview Modelandview = new Modelandview ();
someting invocation of the Request object method Modelandview.addobject ( "id" ,id); Modelandview.setviewname ( "detail" ); return Modelandview; }}
In essence, the controller is a spring component, so in my request method Getdetailid, you can add a httpservletrequest that obtains the current request.
The Request object contains the user ID session, and so on information
-------------------------------------------------------------
Suppose we're going to write an AOP intercept controller to implement our Pointcut transaction, this time
Requestcontextholder this static class is useful,
HttpServletRequest request = ((servletrequestattributes) requestcontextholder.getrequestattributes ()). GetRequest () ;
private static final threadlocal<requestattributes> Requestattributesholder =
New Namedthreadlocal<requestattributes> ("Request attributes");//namedthreadlocal thread Local
publicstatic requestattributes getrequestattributes () { = Requestattributesholder.get ();//Get thread Local request object ifnull) {= Inheritablerequestattributesholder.get ();/ / }return attributes; }
I read spring's source code, which gets the request object that is currently requested.
Work first, make up at night,
Spring MVC acquires the request object in a non-controller layer implementation