【发布时间】:2016-06-26 05:29:15
【问题描述】:
Eclipse 标记的奇怪错误 这是代码
@RequestMapping ("/hello")
public ModelAndView showMessage(@PathVariable(value="name", required=false, defaultValue="World") String name) {
}
所以需要并且 defaultValue 标记为错误
注解类型PathVariable所需的属性未定义
EM ??
Spring 版本是 4.3.0.RELEASE 这是我的导入:
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
是的。当我使用 RequestParam - 一切都好。但是我的sn-p
@RequestMapping ("/hello")
public ModelAndView showMessage(@RequestParam(value="name", required=false, defaultValue="World") String name) {
ModelAndView model = new ModelAndView("helloworld");
model.addObject("name", name);
return model;
}
用 ${name} 打印字符串 - 而不是 name 的值 - 这是否以某种方式链接? 这个参考工作它
<a href="hello?name=Eric">Click Here</a>
【问题讨论】:
-
你用的是什么版本的spring?
-
请发布helloworld视图