在Spring消息代码中获取java.util.Calendar.YEAR [英] Getting java.util.Calendar.YEAR in Spring message code
问题描述
<spring:message code="footer.copyriteText" arguments="NEEDS TO BE DYNAMIC" htmlEscape="false"/>
我需要将NEEDS TO BE DYNAMIC
替换为Calendar.getInstance().get(Calendar.YEAR)
.如何使用EL来实现这一点?
I need to replace NEEDS TO BE DYNAMIC
with Calendar.getInstance().get(Calendar.YEAR)
. How can I achieve this using EL?
推荐答案
如果您不希望像BalusC这样的硬编码解决方案,您可以使用此解决方案
If you don't want hardcode solution like BalusC said you can use this solution
-
编写自定义jstl标记(如c:set)以执行常量路径并返回常量值,然后将该常量值放入Page范围.这可以通过java Reflection完成.
Write custom jstl tag like c:set to execute constant path and return constant value then put the constant value to Page scope. This can be done via java Reflection.
使用标签
<lib:getConstant path='java.util.Calendar.YEAR' var='v'/>
还有
arguments='${v}`
此解决方案可以使用所有常量,并且您可能希望更改常量值而不更改jsp代码.
This solution can work with all constants and you may want change constant values without changing jsp code.
这篇关于在Spring消息代码中获取java.util.Calendar.YEAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!