转载自:http://blog.csdn.net/java20100406/article/details/6232055

通过配置JsonConfig过滤有可能引起循环的字段,如果不这样,根据hibernate的原则会不断的级联查询.
*************************************Action******************************************************
1.对象。
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes( new String[]{ "creator", "module", "testPoints","testProcesses","highLevelRequirements","lowLevelRequirements"} );
String result = JSONObject.fromObject( testCase对象 ,jsonConfig).toString();
2.List数组
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes( new String[]{ "creator", "module", "testPoints","testProcesses","highLevelRequirements","lowLevelRequirements"} );
JSONArray lineitemArray = JSONArray.fromObject( testCases集合List ,jsonConfig);
String result = JSONArray.fromObject(lineitemArray).toString();
3.Map对象
Map map = new HashMap();
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes( new String[]{ "creator", "module", "testPoints","testProcesses","highLevelRequirements","lowLevelRequirements"} );
JSONArray lineitemArray = JSONArray.fromObject( testCases集合List ,jsonConfig);
map.put("testCases", lineitemArray);
String result = JSONObject.fromObject( map对象 ).toString();
************************************struts.xml*******************************************************
<package name="ajax" extends="json-default" namespace="/ajax">
..........
        <action name="childrenAjax" class="**********.AssociationBaseAction" method="getChildren">
            <result name="success" type="json">
                <param name="root">result</param>
            </result>
        </action>
..........
</package>
***************************************javascript****************************************************
1.对象。
  $.ajax({
   type: "POST",
   url: "ajax/oneAjax.html",
            dataType: "json",
   data: "targetId=" + val ,
   success: function(result){
    var json=eval("("+ result + ")");
    $('#selectedResult').append(  "<div ;  
             }
             $('#testCaseDiv').append(url);
       }
    ...........................................
   }
  });

相关文章:

  • 2022-12-23
  • 2021-10-23
  • 2021-06-14
  • 2021-10-15
  • 2021-12-07
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-06-23
相关资源
相似解决方案