Hibernate 如何使用display:table显示数据列表
我必须以jsp格式显示公司名称和他们自己的联系人列表,就像这样Hibernate 如何使用display:table显示数据列表,hibernate,struts2,Hibernate,Struts2,我必须以jsp格式显示公司名称和他们自己的联系人列表,就像这样 -company1 contact1 contact2 -company2 contact1 contact2 .............. 我不知道该怎么做,有什么建议或例子链接吗? PS:在DB中,我有公司和联系人表(由FK关联)如果你使用hibernate,你可以使用DAO来获取信息,一旦你有了信息(即公司的列表),你可以首先使用ajax和json,你必须下载Struts2的json插件 将
-company1
contact1
contact2
-company2
contact1
contact2
..............
我不知道该怎么做,有什么建议或例子链接吗?
PS:在DB中,我有公司和联系人表(由FK关联)如果你使用hibernate,你可以使用DAO来获取信息,一旦你有了信息(即公司的
列表),你可以首先使用ajax和json,你必须下载Struts2的json插件
将其粘贴到Maven pom文件中或不加载jar文件
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>2.3.16.3</version>
</dependency>
在你的动作课上
@ParentPackage("json-default")
@Action(value = "getCompanies", results = {
@Result(type = "json", name = "success")})
public class FetchCompanies extends ActionSupport {
public List<Company> listOfCompanies = new ArrayList<Company>();
@Override
public String execute() {
CompanyDAO dao = new CompanyDAO();
listOfCompanies = dao.query("FROM Company");
return SUCCESS;
}
//Getter Setter
}
这就是html的外观
<div>
<table>
<thead>
<tr>
<th>Attribute1</th>
</tr>
</thead>
<tbody id="yourBody">
//In this section ajax call will insert your information
</tbody>
</table>
</div>
属性1
//在本节中,ajax调用将插入您的信息
$(document).ready(function() {
$.ajax({
url: "getCompanies.action",
type: "POST",
dataType: "json",
success: function(data) {
jQuery.each(data.listOfCompanies, function(i, val) {
$('#yourBody').append("<tr><td>" + val.attribute1OfYourCompanyClass + "</td></tr>");
});
}
});
});
<div>
<table>
<thead>
<tr>
<th>Attribute1</th>
</tr>
</thead>
<tbody id="yourBody">
//In this section ajax call will insert your information
</tbody>
</table>
</div>