【问题标题】:SOmething strange with Spring MVC and EclipseSpring MVC 和 Eclipse 有点奇怪
【发布时间】: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视图

标签: java eclipse spring


【解决方案1】:

value是注解PathVariableSpring提供的唯一属性

org.springframework.web.bind.annotation.PathVariable

所以您在requireddefaultValue 上遇到错误

如果您使用任何其他支持PathVariable 注释的JAX-RSrequireddefaultValue,则将导入语句更改为正确的语句。

编辑

RequestParamrequireddefaultValue,我认为你需要使用RequestParam 而不是PathVariable 有默认值

【讨论】:

  • 为什么这个该死的 Tomcat 无法获取我更新的 index.jsp ??!! - 其他页面没问题
  • 请不要在现有帖子中添加问题,请创建一个新问题并发布
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-09
  • 1970-01-01
  • 2016-09-10
  • 2013-02-09
  • 2016-01-03
  • 2023-03-11
  • 1970-01-01
相关资源
最近更新 更多