在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;
}
以上是常用的幾種獲取請求參數的方式,根據具體的需求選擇適合的方式來獲取參數。