ITeye博客

struts格式化问题

loveseaside · 2010-05-11 10:09 · struts · 企业架构 · Apache · DB2 · Struts · SQL · Bean · Markdown

日期格式化
db2的字段类型定义为TIMESTAMP 显示毫秒,(hibernate保存数据时候也是如此)
 2010-05-11 10:06:30.068  2010-05-20 00:00:00.0
用struts bean:write标签进行格式化输出
<bean:write name="" property="" format="yyyy"/>             2010
<bean:write name="" property="" format="yyyy-MM-dd "/>      2010-05-20
<bean:write name="" property="" format="yyyy-MM-dd HH:mm:ss"/> 2010-05-20 00:00:00.0

数字格式
用struts bean:write标签进行格式化输出
<bean:write name="" property="" format="0000"/>
不足四位前补充0;0008如<bean:write name="" property="" format="0000"/> 显示为0008,而不是8
<bean:write name="" property="" format="###0"/>
不足四位前不补充0;0008如<bean:write name="" property="" format="###0"/> 显示为8,而不是0008
<bean:write name="" property="" format="###0.00"/>
#前面不补充0,小数点后不足2位补0; 0008.00如<bean:write name="" property="" format="###0.00"/> 显示为8.00

<bean:write name="" property="" format="#,###"/>

,表示分割 8000如<bean:write name="" property="" format="#,###"/> 显示为8,000
项目中的变量大多以同一格式输出,可以在struts-config.xml中的message-resources节点统一进行定义,如:org.apache.struts.taglib.bean.format.float=0,000.00

实际处理时页面上定义的format拥有较高的优先级。

附录:

序号          格式化参数                                                                       适用类型
1    org.apache.struts.taglib.bean.format.sql.timestamp             java.sql.Timestamp
2    org.apache.struts.taglib.bean.format.sql.date                      java.sql.Date
3    org.apache.struts.taglib.bean.format.sql.time                       java.sql.Time
4    org.apache.struts.taglib.bean.format.date                            java.util.Date
5    org.apache.struts.taglib.bean.format.int                             Byte,Short,Integer,Long,BigInteger
6    org.apache.struts.taglib.bean.format.float                          Float,Double,BigDecimal

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。