The problem is that the original system has the code of the log operation, but the log is not saved to the database eventually.
Interceptor Configuration in XML:
< Mvc:interceptor > < path= "/admin/**"/> <id= " Loginterceptor " class=" Com.store.interceptor.LogInterceptor"/> </ Mvc:interceptor >
Loginterceptor:
@Override Public voidPosthandle (httpservletrequest request, httpservletresponse response, Object handler, Modelandvi EW Modelandview)throwsException {List<LogConfig> Logconfigs =Logconfigservice.getall (); if(Logconfigs! =NULL) {String path=Request.getservletpath (); for(LogConfig logconfig:logconfigs) {if(Antpathmatcher.match (Logconfig.geturlpattern (), path)) {String username=Adminservice.getcurrentusername (); String Operation=logconfig.getoperation (); String operator=username; String content=(String) request. getattribute (Log.log_content_attribute_name); String IP=request.getremoteaddr (); Request.removeattribute (Log.log_content_attribute_name); StringBuffer parameter=NewStringBuffer (); Map<string, string[]> parametermap =request. Getparametermap (); if(Parametermap! =NULL) { for(Entry<string, string[]>Entry:parametermap. EntrySet ()) {String parametername=Entry.getkey (); if(!arrayutils.contains (Ignoreparameters, parametername)) {string[] parametervalues=Entry.getvalue (); if(ParameterValues! =NULL) { for(String parametervalue:parametervalues) { Parameter.append (parametername+ "=" + ParameterValue + "\ n"); } } } } } Log log=NewLog (); Log.setoperation (operation); Log.setoperator (operator); Log.setcontent (content); Log.setparameter (Parameter.tostring ()); Log.setip (IP); Logservice.save (log); Break; } } } }
When you debug your code, you find that the value of path is always "". Because "", it is not allowed to enter if (Antpathmatcher.match (), Logconfig.geturlpattern (), path) of the judgment statement, the Logservice.save (log) Inside the statement can not be executed naturally.
Antpathmatcher is spring's tool class, specifically Baidu.
The implementation of Loginterceptor can also be Baidu.
Later, instead:
@Override Public voidPosthandle (httpservletrequest request, httpservletresponse response, Object handler, Modelandvi EW Modelandview)throwsException {List<LogConfig> Logconfigs =Logconfigservice.getall (); if(Logconfigs! =NULL) { //String Path = Request.getservletpath ();String URL =Request.getrequesturl (). toString (); String Path= Url.substring (16); for(LogConfig logconfig:logconfigs) {if(Antpathmatcher.match (Logconfig.geturlpattern (), path)) {String username=Adminservice.getcurrentusername (); String Operation=logconfig.getoperation (); String operator=username; String content=(String) request. getattribute (Log.log_content_attribute_name); String IP=request.getremoteaddr (); Request.removeattribute (Log.log_content_attribute_name); StringBuffer parameter=NewStringBuffer (); Map<string, string[]> parametermap =request. Getparametermap (); if(Parametermap! =NULL) { for(Entry<string, string[]>Entry:parametermap. EntrySet ()) {String parametername=Entry.getkey (); if(!arrayutils.contains (Ignoreparameters, parametername)) {string[] parametervalues=Entry.getvalue (); if(ParameterValues! =NULL) { for(String parametervalue:parametervalues) { Parameter.append (parametername+ "=" + ParameterValue + "\ n"); } } } } } Log log=NewLog (); Log.setoperation (operation); Log.setoperator (operator); Log.setcontent (content); Log.setparameter (Parameter.tostring ()); Log.setip (IP); Logservice.save (log); Break; } } } }
Solved.
About interceptors implementing code debugging for log storage to DB