SpEL (@NumberFormat) 不起作用
----SampleVO
@NumberFormat(pattern = "###,##0")
private int money=100000;
-----controller
@RequestMapping(value="/com/spelSample.do")
public String spelSample(SampleVO sampleVO, Model model){
model.addAttribute("sampleVO", sampleVO);
return "sampleResult";
}
-------sampleResult.jsp
money: <spring:eval expression="sampleVO.money"/>
-----expectation
money : 100,000
------但是,result是
money : 100000
什么问题呢? 我应该怎么办?
----SampleVO
@NumberFormat(pattern = "###,##0")
private int money=100000;
-----controller
@RequestMapping(value="/com/spelSample.do")
public String spelSample(SampleVO sampleVO, Model model){
model.addAttribute("sampleVO", sampleVO);
return "sampleResult";
}
-------sampleResult.jsp
money: <spring:eval expression="sampleVO.money"/>
-----expectation
money : 100,000
------but, result is
money : 100000
what is the problem?
what should i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自
@NumberFormat
文档:您正在原始字段上使用它。显然这没有被涵盖。使用
Integer
而不是int
。编辑:更准确地说,并没有涵盖 java.lang.Number 的每个可能的子类。以下是
NumberFormatAnnotationFormatterFactory
:这意味着缺少并发 api 中的 Atomic* 类,以及 Commons/Lang 等框架中的所有自定义 Number 实现。
更新:(参见注释)您还需要添加
到您的 context.xml。From the
@NumberFormat
docs:You are using it on a primitive field. Apparently that is not covered. Use
Integer
instead ofint
.Edit: to be more precise, not every possible subclass of
java.lang.Number
is covered. Here is the relevant excerpt fromNumberFormatAnnotationFormatterFactory
:This means the Atomic* classes from the concurrent api are missing, as well as all custom Number implementations from frameworks like Commons/Lang etc.
Update: (see comments) you also need to add
<mvc:annotation-driven>
to your context.xml.