我想使用HttpServletRequest.getParameter获取Interceptor放入的参数,Interceptor该如何放入参数
时间: 2023-12-03 17:02:05 浏览: 76
jfinal中拦截器(Interceptor)的参数注入
在Interceptor中,可以通过实现preHandle方法获取HttpServletRequest对象,并在其中设置参数,例如:
```
public class MyInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
request.setAttribute("myParam", "myValue");
return true;
}
}
```
在Controller中,可以通过HttpServletRequest.getParameter方法获取Interceptor中设置的参数,例如:
```
@Controller
public class MyController {
@RequestMapping("/myUrl")
public String myMethod(HttpServletRequest request) {
String myParam = request.getParameter("myParam");
return "myPage";
}
}
```
阅读全文