尝试使用字符串文字value
对于 name 属性而不是用 EL 解析它
<spring:bind path="value">
<input type="text" name="value" value="${value}"/>
</spring:bind>
另外,将字段值移动到新对象中。目前我不相信代码正在使用控制器中的字段或控制器中的吸气剂。
public class MyForm(){
@NumberFormat(style = Style.CURRENCY)
private Double value = 50.00;
@ModelAttribute("value")
@NumberFormat(style = Style.CURRENCY)
public Double getValue() {
return value;
}
}
然后将对象添加到控制器中的模型中:
@RequestMapping(method = RequestMethod.GET)
public ModelAndView loadForm(@ModelAttribute("user") User user) {
ModelAndView instance
modelAndView.addObject("myForm", new MyForm());
return modelAndView;
}
然后通过jsp访问:
<spring:bind path="myForm.value">
<input type="text" name="${status.expression}" value="${status.value}"/>
</spring:bind>
<spring:bind path="myForm.value">
${status.value}
</spring:bind>
目前代码的主要问题是它没有使用字段/访问器,它只是在模型中放置一个值,该模型不使用任何带注释的字段/方法。
参考:http://www.captaindebug.com/2011/08/using-spring-3-numberformat-annotation.html#.UOAO_3fghvA http://www.captaindebug.com/2011/08/using-spring-3-numberformat-annotation.html#.UOAO_3fghvA
Spring MVC spring:bind 标签如何工作?status.expression 和 status.value 的含义是什么? https://stackoverflow.com/questions/614729/how-is-the-spring-mvc-springbind-tag-working-and-what-are-the-meanings-of-statu