在Spring MVC中,可以通过以下几种方式获取请求参数:
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");
// 处理参数
...
return true;
}
public boolean preHandle(@RequestParam("param1") String param1, @RequestParam("param2") String param2, HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 处理参数
...
return true;
}
public boolean preHandle(@PathVariable("param1") String param1, @PathVariable("param2") String param2, HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 处理参数
...
return true;
}
以上是常用的几种获取请求参数的方式,根据具体的需求选择适合的方式来获取参数。