2016-08-14 41 views
0

我已經與現在掙扎了幾個星期,我有一個方法:@RequestParam春不工作

@RequestMapping(method = RequestMethod.GET) 
    public ModelAndView update(
      HttpServletRequest request, 
      HttpServletResponse response, 
    @RequestParam(value = "id", required = true) String id) throws Exception 
    { 
     model = new ModelAndView("/jspadmin/game/update"); 

     getLog().error("::: valor del string: " + request.getParameter("id")); 
     getLog().error("::: valor del string: de ruta" + id); 
    } 

這個代碼是內部的的MultiActionController,但我不能獲得ID從@RequestParam anotation值

我已經anotation在aplicationContext.xml

即時不使用anotations所有,只是在該方法中,我不知道如果T驅動他控制器需要一個@Controller anotation強制性的使工作中的方法,我不知道什麼即時通訊失蹤,感謝提前傢伙工作。

+1

你有在控制器級設置了@ RequestMapping的'value'屬性?是的,在控制器類上需要'@ Controller'。 –

+0

我在xml中創建控制器,如果我把@controller放在類中,這很重要嗎?因爲我得到下一個錯誤: –

回答

1

嘗試用註解@Controller:

@Controller 
@RequestMapping("/rootUrl") 
public class MyController... 

和行動:

@RequestMapping(value="/url", method = RequestMethod.GET) 
public String update(@RequestParam... 
0

請使用下面的代碼,只需添加值的一些模式在請求映射

@RequestMapping(value = "/save", method = RequestMethod.GET) 
public ModelAndView update(HttpServletRequest request, HttpServletResponse response, 
     @RequestParam(value = "id", required = true) String id) throws Exception { 
    System.out.println("Inside Save id is " + id); 
    return new ModelAndView("index"); 
} 
+1

給出的解決方案可能工作請試用 – Dilip