如何为全局范围自定义Struts Json插件日期格式

viv*_*via 2 json struts2

至于标题.我不想在每个getXXXDate()上添加一个注释(@Json(format ="yyyy-MM-dd HH:mm:ss"),任何人都可以提供解决方案吗?

小智 6

您可以在对象类中使用struts 2 json插件,例如:

        private Date createdDate;

        @JSON(format="MM/dd/yyyy") 
  // or @JSON(format="date.format") from bundle resource properties files
        public Date getCreatedDate() {
            return createdDate;
        }

        public void setCreatedDate(Date createdDate) {
            this.createdDate = createdDate;
        }
Run Code Online (Sandbox Code Playgroud)