我在struts.xml中有一个常量,用于设置dateformat

<constant name="date.format" value="dd-MMM-yyyy" />


我想将此常量用作setter方法的bean类中的注释值:

@JSON(format="date.format")
public void setEndDate(Date endDate) {
  this.endDate = endDate;
}


这可能吗?

最佳答案

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;
}


Struts通过调用date.format注入setFormat,您可以在操作方法中使用它。

关于java - 使用来自struts.xml的内容作为注释值-Struts2 Java,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36171762/

10-11 19:25
查看更多