我期待通過一些彈簧3 MVC控制器代碼,我看到@RequestParam用於某些參數,而不是爲別人。實施例,其中沒有使用它:何時在Spring MVC中不需要@RequestParam註解?
@RequestMapping(value = "/experiments", method = RequestMethod.GET)
public String getExperimentsPage(ExperimentSearchCriteria criteria, Map<String, Object> model) {
// method body here
}
當@RequestParam(或類似的參數 - 指定註釋)不需要?
我的測試顯示,如果你有一個'@ Controller'「動作」法非註解參數,Spring會嘗試綁定類似命名的請求參數(否則忽略參數) 。但是,當您打算使用請求參數填充操作方法參數時,最好是明確的並使用@ RequestParam註解。當然,它可以通過'@ RequestParam'的屬性(如默認和必需)調整用法來爲您提供更多的控制權。 – 2016-11-10 20:48:51