发布于 2016-08-16 09:13:27 | 126 次阅读 | 评论: 1 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Struts Java MVC框架

Struts 是Apache软件基金会(ASF)赞助的一个开源项目。它最初是Jakarta项目中的一个子项目,并在2004年3月成为ASF的顶级项目。它通过采用JavaServlet/JSP技术,实现了基于Java EEWeb应用的MVC设计模式的应用框架,是MVC经典设计模式中的一个经典产品。


struts2中action实现ModelDriven后无法返回json的解决方法,需要的朋友可以参考一下


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>



最新网友评论  共有(1)条评论 发布评论 返回顶部
enov 发布于2016-10-05 05:45:05
非常棒,顶了
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务