1
private Integer iDisplayLength ;

public Integer getIDisplayLength() {
        return iDisplayLength;
    }

    public void setIDisplayLength(Integer iDisplayLength) {
        this.iDisplayLength = iDisplayLength;
    }

如果请求包含iDisplayLength,则设置完美,我可以看到实际的价值。但是当响应返回(json-response)时,它会返回

IDisplayLength代替iDisplayLength

对我来说似乎是一个错误。我做错了吗?那些 getter 和 setter 不正确吗?

我的 struts.xml 看起来像:

<action name="c/list" class="actions.MyAction" method="list">
            <result name="*" type="json"></result>
</action>

更新

我浏览了插件源代码:https ://github.com/apache/struts2/blob/STRUTS_2_3_15_X/plugins/json/src/main/java/org/apache/struts2/json/JSONWriter.java

复制它用来计算字段名称的方法后:

public static void main(String[] args) throws Exception {
        Class clazz = new IoAction().getClass();

        BeanInfo info = getBeanInfoIgnoreHierarchy(clazz);

        PropertyDescriptor[] props = info.getPropertyDescriptors();

        boolean hasData = false;
        for (PropertyDescriptor prop : props) {
            System.out.println("Field Name : "+prop.getName());
        }
    }

其中IoAction有 getter/setter,例如:

public String getISortCol_0() {
        return iSortCol_0;
    }

    public void setISortCol_0(String iSortCol_0) {
        this.iSortCol_0 = iSortCol_0;
    }

上面的代码将字段名称打印ISortCol_0为不正确(恕我直言),它应该返回iSortCol_0它是 java 反射 API 中的错误吗?

4

0 回答 0