struts2中action实现ModelDriven后无法返回json的解决方法
程序员文章站
2024-02-13 20:20:10
复制代码 代码如下: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;
}
}
<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>
复制代码 代码如下:
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>
下一篇: ssh生成随机数字验证码操作步骤