在Spring MVC中,可以通過以下幾種方式獲取請(qǐng)求參數(shù):
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");
// 處理參數(shù)
...
return true;
}
public boolean preHandle(@RequestParam("param1") String param1, @RequestParam("param2") String param2, HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 處理參數(shù)
...
return true;
}
public boolean preHandle(@PathVariable("param1") String param1, @PathVariable("param2") String param2, HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 處理參數(shù)
...
return true;
}
以上是常用的幾種獲取請(qǐng)求參數(shù)的方式,根據(jù)具體的需求選擇適合的方式來獲取參數(shù)。