欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

struts2中action实现ModelDriven后无法返回json的解决方法

程序员文章站 2023-11-16 22:24:22
复制代码 代码如下:public class deviceaction extends abstractaction implements modeldriven

复制代码 代码如下:

public class deviceaction extends abstractaction implements modeldriven<device> {
    private static log log = logfactory.getlog(deviceaction.class);
    private device device=new device(); //只能json化 模型驱动的bean
    private string result; //无法返回reslut的json值

   
    public string getresult(){
        return result;
    }
    public void setresult(string result){
        this.result=result
    }
    public devicedto getmodel() {
        return device;
    }
    public device getdevice() {
        return device;
    }
    public void setdevice(device device) {
        this.device = device;
    }
}            

xml配置:

复制代码 代码如下:

<action name="querypu"
            class="com.jxj.bss.web.actions.deviceaction"
            method="querypu">
            <interceptor-ref name="islogin"></interceptor-ref>
            <result type="json">
                <param name="includeproperties">
                    resultcode
                </param>
            </result>
        </action>

解决办法:

复制代码 代码如下:

<action name="querypu"
            class="com.jxj.bss.web.actions.deviceaction"
            method="querypu">
            <interceptor-ref name="islogin"></interceptor-ref>
            <result type="json">
                <param name="root">action</param>
                <param name="includeproperties">
                    resultcode
                </param>
            </result>
        </action>