后台
model数据
java
@Entity
public class Person {
private int id; //自增长
private String identy; //身份证
private String name; //姓名
private Date birthday; //出生日期
private Person daddy; //父亲
private Person mother; //母亲
Action
用Hibernate将数据读取出来,List对象;然后转为Json对象,传回前台
java
@Resource HibernateTemplate hibernateTemplate;
@RequestMapping("/showPerson")
public void showPerson(HttpServletResponse response){
List<Person> personList = new ArrayList<Person>();
personList = hibernateTemplate.find("from Person");
String json = JSONUtils.writeValueAsString(personList); //转为json对象
HTMLUtils.writeJosn(response, json); //json转到前台
}
前台
在th的data-options字段要注意外,还要注意formatter字段,对应在js的方法 进行数据处理
java
<table class="easyui-datagrid" title="个人信息表" style="width:1200px;height:500px"
data-options="rownumbers:true,singleSelect:true,url:'<%=request.getContextPath()%>/showPerson.do',method:'get'">
<thead>
<tr>
<th data-options="field:'identy',width:220,align:'center'" rowspan="2">身份证号</th>
<th data-options="field:'name',width:200,align:'center'" rowspan="2">姓名</th>
<th data-options="field:'birthday',width:200,align:'center'" rowspan="2">出生日期</th>
<th colspan="2">家庭关系</th>
</tr>
<tr>
<th data-options="field:'daddy',width:260,align:'center'" formatter="deal_daddy">父上大人</th>
<th data-options="field:'mother',width:260,align:'center'" formatter="deal_mother">母上大人</th>
</tr>
</thead>
</table>
JS
java
<script>
function deal_daddy(value,row,rowIndex){
if(row.daddy!=undefined){
return row.daddy.name;
}
}
function deal_mother(value,row,rowIndex){
if(row.mother!=undefined){
return row.mother.name;
}
}
</script>