`

ZK + Spring + Hibernate最简单的例子

    博客分类:
  • ZK
阅读更多
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)、页面效果图
  • 描述: 页面效果图
  • 大小: 27.5 KB
5
3
分享到:
评论
4 楼 yianpuodiaotu 2009-03-10  
谢谢,现在项目正好使用它 
3 楼 qhitsky 2009-02-03  
看起来是很简单的,不过最好还是把例子的完整源码也贴出来!
2 楼 cysunc 2008-09-25  
自己写的。
很简单,就是读spring的配置文件,一个加载spring的方法,一个获取bean的方法。
类里面做一个判断,不重复加载配置文件即可。
好处在于可以在非web容器中写测试用例。
1 楼 key232323 2008-09-21  
SpringFactory这个类你是从哪里来的??

相关推荐

Global site tag (gtag.js) - Google Analytics