[英]Using Contants from struts.xml as Annotation Value - Struts2 Java
I have a constant in struts.xml which sets the dateformat我在 struts.xml 中有一个常量,它设置了日期格式
<constant name="date.format" value="dd-MMM-yyyy" />
I want to use this constant as a annotation value in a bean class for a setter method like:我想将此常量用作 bean 类中的注释值,用于 setter 方法,例如:
@JSON(format="date.format")
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
Is this possible?这可能吗?
The struts has an internal dependency injection, which you can use as: struts 有一个内部依赖注入,您可以将其用作:
public class Sample extends BaseActionSupport {
private String format;
public String execute(){
//In you action
System.out.println("The format is" + format);
}
@com.opensymphony.xwork2.inject.Inject("date.format")
public void setFormat(String format) {
this.format = format;
}
The struts injects the date.format
by calling setFormat
and you can use it in action methods. struts 通过调用setFormat
注入date.format
,您可以在操作方法中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.