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时 - 一切正常。但我的片段
@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>
答案 0 :(得分:0)
value
是注释PathVariable
Spring提供的唯一属性
org.springframework.web.bind.annotation.PathVariable
因此,您在required
和defaultValue
如果您使用支持JAX-RS
和PathVariable
required
注释的任何其他defaultValue
,请将导入语句更改为正确的注释。
修改强>
RequestParam
有required
和defaultValue
,我认为您需要使用RequestParam
代替PathVariable
才能拥有默认值