[英]How to read request parameter values Using HandlerInterceptor in spring?
我正在使用HandlerInterceptor触发我的应用程序中发生的所有事件/动作,并将其保存到审计表中。 在表中,我保存了诸如服务器名,会话,参数等信息。
因此,使用HandlerInterceptor,如何读取我在控制器中传递的所有这些参数值和pathvariable值。
这是我的代码:
public class AuditInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
LOG.debug("URL path"+request.getRequestURI());
return true;
}
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
LOG.debug("URL PATH :"+request.getRequestURI());
}
}
我的控制器类在这里输入代码:
public class ABCDController {
@RequestMapping(value="categories",method=RequestMethod.GET)
@ResponseBody
public List<Category> getCategoryList(@RequestParam String divisions){
return service.getCategoryList(divisions);
}
}
因此,如何使用HandlerInterceptor的HttpServletRequest请求对象读取参数名称和值。
Servlet API提供了一种读取请求参数的方法。 例如,
ServletRequest.getParameterMap()
返回请求参数的键值映射。
但是,对于Path变量和值,我不知道Spring MVC是否提供了简化的方法,但是再次使用Servlet API,您可以使用HttpServletRequest.getRequestURI()
读取URI。 您必须具有自己的逻辑,才能将其拆分为适当的Path参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.