ZK + Spring + Hibernate最简单的例子

ZK + Spring + Hibernate最简单的例子

1、Spring+Hibernate配置起来很简单,具体就不细说了,网上多的是。

2、ZK显示页面
【query.zul】
<?xml version="1.0" encoding="UTF-8"?>
<window>
<button label="查询"></button>
<vbox>
<listbox id="testListID" width="800px" rows="5" use="chanson.common.web.ui.ListTestBean">
<listhead>
<listheader label="姓名"/>
<listheader label="性别"/>
<listheader label="生日"/>
<listheader label="薪资"/>
</listhead>
<listitem value="${each.id}" forEach="${testList}">
<listcell label="${each.name}"/>
<listcell label="${each.sex}"/>
<listcell label="${each.birthday}"/>
<listcell label="${each.money}"/>
</listitem>
</listbox>
</vbox>
</window>

《说明》:
A、<?xml version="1.0" encoding="UTF-8"?>
这个别忘记了,刚学的时候就是因为它报了不少错误。
B、use="chanson.common.web.ui.ListTestBean"
这个类就是衔接前后台的关键类。
C、${*.*}这个是标准的EL写法。


3、ListTestBean——最关键的衔接类
public class ListTestBean extends Listbox {

public void onCreate() {
ITestLogic testLogic = (ITestLogic) SpringFactory
.getBeanFactory().getBean("testLogic");
List testList = testLogic.find("from Test");
Iterator it = testList.iterator();
while(it.hasNext()) {
Test test = (Test) it.next();
Long id = test.getId();
String name = test.getName();
Integer sex = test.getSex();
Date birthday =test.getBirthday();
Double money = test.getMoney();

Listitem listitem = new Listitem();
listitem.setValue(id);
listitem.setParent(this);

Listcell nameCell = new Listcell(name);
Listcell sexCell = new Listcell(sex.toString());
Listcell birthdayCell = new Listcell(birthday.toString());
Listcell moneyCell = new Listcell(money.toString());
nameCell.setParent(listitem);
sexCell.setParent(listitem);
birthdayCell.setParent(listitem);
moneyCell.setParent(listitem);
}
}
}
《说明》:
A、例子是一个简单的查询,所以看起来也比较简单。
B、该类的作用有点像似servlet,只是省略了页面跳转
C、setter/getter真是麻烦,得找找更简洁的方法


【附录】
1)、数据库设计——test表
CREATE TABLE `test` (
`id` decimal(22,0) NOT NULL default '0',
`name` varchar(100) default NULL,
`sex` int(1) default NULL,
`birthday` datetime default NULL,
`money` decimal(15,4) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2)、其他应该没什么了吧?
3)、页面效果图
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值