1.
<s:if test="title.length()>20">
<s:property value="title.substring(0,20)+'...'"/>
</s:if>
2.或者
<s:if test="%{title.length()>300}">
<s:property value="title.substring(0,300)+'...'"/>
</s:if>
struts2中格式化输出数字和日期、截取小数点后两位数的方法 收藏
struts2中格式化输出数字和日期的方法,struts2截取小数点后两位数
1.写一个Messages.properties配置文件:
#number:
global.format.money={0,number,#0.00##}
global.format.money02={0,number,##0.00}
#datetime:
global.format.date={0,date,yyyy-MM-dd}
global.format.time={0,date,HH:mm:ss}
global.format.datetime={0,date,yyyy-MM-dd HH:mm:ss}
global.format.datetime02={0,date,yyyy-MM-dd HH:mm}
其中#number为控制数字格式的,一般用于控制钱的位数;#datetime是控制时间格式
2.页面上:<s:text name="global.format.date"><s:param value="deployDate" /></s:text>
其中:<s:text name="global.format.date">控制你要显示的时间格式
<s:param value="deployDate" />是你要显示的时间
JSP文件
格式化时间: <s:text name="global.format.date"><s:param value="publishTime"></s:param></s:text>
格式化数字: <s:text name="global.format.money"><s:param value="price"/></s:text>
二:
<input type="text" value="<s:date name="deployDate" format="yyyy-MM-dd" />" />
其中name="deployDate"是你要显示的时间,format="yyyy-MM-dd"是显示的格式
<s:if test="title.length()>20">
<s:property value="title.substring(0,20)+'...'"/>
</s:if>
2.或者
<s:if test="%{title.length()>300}">
<s:property value="title.substring(0,300)+'...'"/>
</s:if>
struts2中格式化输出数字和日期、截取小数点后两位数的方法 收藏
struts2中格式化输出数字和日期的方法,struts2截取小数点后两位数
1.写一个Messages.properties配置文件:
#number:
global.format.money={0,number,#0.00##}
global.format.money02={0,number,##0.00}
#datetime:
global.format.date={0,date,yyyy-MM-dd}
global.format.time={0,date,HH:mm:ss}
global.format.datetime={0,date,yyyy-MM-dd HH:mm:ss}
global.format.datetime02={0,date,yyyy-MM-dd HH:mm}
其中#number为控制数字格式的,一般用于控制钱的位数;#datetime是控制时间格式
2.页面上:<s:text name="global.format.date"><s:param value="deployDate" /></s:text>
其中:<s:text name="global.format.date">控制你要显示的时间格式
<s:param value="deployDate" />是你要显示的时间
JSP文件
格式化时间: <s:text name="global.format.date"><s:param value="publishTime"></s:param></s:text>
格式化数字: <s:text name="global.format.money"><s:param value="price"/></s:text>
二:
<input type="text" value="<s:date name="deployDate" format="yyyy-MM-dd" />" />
其中name="deployDate"是你要显示的时间,format="yyyy-MM-dd"是显示的格式
本文介绍Struts2框架中如何使用配置文件实现数字和日期的格式化输出,包括控制金额显示的小数位数和时间格式。通过简单的示例代码展示了如何在JSP页面上应用这些格式。

被折叠的 条评论
为什么被折叠?



