struts2中使用json插件执行ajax处理时,如果方法名是get方法的时候,方法会莫名其妙的执行两次。
原因:
struts2 中JSON的原理是在ACTION中的get方法都会序列化,所以前面是get的方法只要没指定不序列化,都会执行解决方法1、Action中的业务方法前别加get 或者 set(属性的get set 除外)
2、用@JSON(serialize=false)指定方法不序列化如import com.googlecode.jsonplugin.annotations.JSON;@JSON(serialize=false)
public String getChild() throws Exception{
..............
..............
return "success";
}
原因:
struts2 中JSON的原理是在ACTION中的get方法都会序列化,所以前面是get的方法只要没指定不序列化,都会执行解决方法1、Action中的业务方法前别加get 或者 set(属性的get set 除外)
2、用@JSON(serialize=false)指定方法不序列化如import com.googlecode.jsonplugin.annotations.JSON;@JSON(serialize=false)
public String getChild() throws Exception{
..............
..............
return "success";
}
本文详细解析了在Struts2框架中,当使用JSON插件处理AJAX请求时,若方法名为get可能会导致意外执行两次的问题,并提供了两个解决方案:避免在业务方法前使用get或set关键字,或通过注解@JSON(serialize=false)明确指定方法不应被序列化。
264

被折叠的 条评论
为什么被折叠?



