一定要说明:这不是我写的,copy的,地址:http://java20100406.iteye.com/blog/946580
=======================>自己添加<============================
Hibernate many-to-one双向关联中,查询many方时会将one方数据顺带着查询,同时one中会有List<Many>,然后又会去查Many中的数据...周而复始,结果=>完了,json解析失败。
解决方法,通过JsonConfig设置过滤字段(setExcludes)
举例如:
**********===model===************
public class One {
private int id;
List<Many> manyList;
...
}
public class Many {
private int id;
private One one;
...
}
********** daoImpl ************
String HQLStr = "from Many";
********** action ************
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes(new String[]{"manyList"});//关键在这,过滤掉这个
JSONArray jsonArr = new JSONArray();
jsonArr.add(tempList, jsonConfig);//tempList是通过Hibernate查询的结果集
=======================>自己添加<============================
正文如下:
通过配置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 id=" + json.id +"><input type='checkbox' name='selected' value='" + json.id + "'>"+ json.id + " : " + json.name +"</div>" );
}
});
2.List数组
$.ajax({
type: "POST",
url: "ajax/childrenAjax.html",
dataType: "json",
data: url,
error: function(){
alert("<fmt:message key='errors.msg'/>");
},
success: function(result){
var org1=eval("("+ result + ")");
for(var i=0;i<org1.length;i++){
menuTree.add(org1[i].id,ID,org1[i].id + " : " + org1[i].name);
}
}
});
3.Map对象
$.ajax({
type: "POST",
url: "ajax/associationAjax.html",
dataType: "json",
data: "associationObjectIds=" + idString () ,
success: function(result){
var json=eval("("+ result + ")");
var dataItems = json.dataItems;
var testCases = json.testCases;
var sysReqs = json.sysReqs;
var hlrReqs = json.hlrReqs;
var llrReqs = json.llrReqs;
var funcInfos = json.funcInfos;
.....................................................
if (testCases.length != 0){
$('#testCaseDiv').empty();
var url = "";
for(var i =0;i<testCases.length;i++){
url = url + "<div id='testCaseDiv" + i + "' style='height:30px;overflow:hidden;'>";
url = url + "<table width=100% border=1 cellspacing=0 cellpadding=1 bordercolor=ffffff bordercolordark=#ffffff bordercolorlight=B9B9B9>";
url = url + "<tr align=center>";
url = url + "<td width=20% height=28 bgcolor=#EFEFEF><fmt:message key='summary.html.testCase.Id'/></td>";
url = url + "<td width=30% height=28 align=left>";
url = url + testCases[i].id + " ";
url = url + "</td>";
url = url + "<td width=20% height=28 bgcolor=#EFEFEF><fmt:message key='summary.html.testCase.creator'/></td>";
url = url + "<td width=30% height=28 align=left >";
url = url + "<span style='float:left' id='testCaseSpan" + i + ".creator'>" + testCases[i].creatorName + "</span>";
url = url + "<span style='float:right' id='testCaseSpan" + i + "' onclick=shoppingcat('testCaseDiv" + i + "','testCaseSpan" + i + "') title=open><img src='./images/down.png'/></span>";
url = url + " ";
url = url + "</td>";
url = url + "</tr>";
url = url + "<tr align=center>";
url = url + "<td width=20% height=28 bgcolor=#EFEFEF><fmt:message key='summary.html.testCase.name'/></td>";
url = url + "<td colspan=3 height=28 align=left><span id='testCaseSpan" + i + ".name'>" + testCases[i].name + "</span> </td>";
url = url + "</tr>";
url = url + "</tr>";
url = url + "<tr align=center>";
url = url + "<td width=20% height=60 bgcolor=#EFEFEF><fmt:message key='summary.html.testCase.description'/></td>";
url = url + "<td width=80% height=60 colspan=3 align=left ><span id='testCaseSpan" + i + ".description'>" + testCases[i].description + "</span>";
url = url + "</td>";
url = url + "</tr>";
url = url + "</table>";
url = url + "</div>";
}
$('#testCaseDiv').append(url);
}
...........................................
}
});
分享到:
相关推荐
sysdiagnose_2024.04.08_00-02-200800_iPhone-OS_iPhone_21F5048f.tar.gz
cydia_1.0.3366-1_iphoneos-arm-安装包-图标不见了
byg.iosios.net.crane-rootless_1.3.14-6_iphoneos-arm64.deb
bitesms_6.2_iphoneos-arm_fix3
标题“redsn0w-win_0.9.4”指的是一个针对Windows操作系统的越狱工具,主要用于iPhone设备。redsn0w是著名的iOS越狱工具之一,由知名的黑客团队Dev Team开发。版本号0.9.4表明这是该工具的一个早期版本,尽管较旧,...
Reveal.deb,适用于越狱设备
iOS上强大的文件管理工具iFile的deb文件
《OpenCV在iPhone上的应用实例解析》 OpenCV(Open Source Computer Vision Library)是一个开源的计算机视觉库,它包含了众多图像处理和计算机视觉的算法,广泛应用于图像识别、人脸识别、图像分割、物体检测等...
用来监控IP联网
一句命令 打印设备安装的App 可选用户App || 系统App 等 适用于越狱设备
netskao.wcpureextension_4.2-6_iphoneos-arm.deb
com.iosrxwy.QQMusicNoAds_0.1-2_iphoneos-arm.deb
libsigc++_2.2.3-4_iphoneos-arm.deb
在这个案例中,文件名"OpenSSL-for-iPhone-master.zip"表明我们下载的是一个专门为iPhone优化过的OpenSSL分支。 2. **准备编译环境**:确保你已经安装了Xcode和Command Line Tools,这些工具包含了编译所需的gcc或...
apt.sileo.mterminal2_1.4-6_iphoneos-arm.deb
《Objective-C中的Logo更换工具——ChangeLogo-master_iphone_详解》 在iOS应用开发中,品牌形象的呈现往往离不开精心设计的Logo。为了方便开发者在Objective-C项目中快速、灵活地更改应用的Logo,出现了名为...
shsh(iphone3,2) iPhone_4-6.1.2_(10B146)-blobs.ifaith
000000C85015A34F_iPhone_4-6.1.3_(10B329)-blobs.ifaith
标题中提到的知识点是“西蒙iphone-OpenGL_ES_教程”,这表明本教程专注于iPhone平台上OpenGL ES的应用。OpenGL ES(Open Graphics Library for Embedded Systems)是一种图形API(应用程序编程接口),它是OpenGL专...
降级必备,000001FCEF08654C_iPhone_4-6.0.1_(10A523)-blobs