2014.02.12 JFinal 之Model

来源:互联网 发布:js注释方法 编辑:程序博客网 时间:2024/04/28 13:58

Model 中最重要的还是其中的属性:attrs(一个map),它将数据库字段名和值以键值对的方式保存在这个map中

它的优点是,实体类的属性和数据库表中的字段并不需要一一对应,而是可以自由扩展,如下代码:

方式一:

String sql_notiList = "select * from notification where nid=?";

 
Notification entity = NotificationService.service.findFirst(sql_notiList, getPara("nid"));


方式二:

String sql_notiList = "select n.*, p.pname from project p,notification n where p.pid = n.pid and n.nid=?";
 
Notification entity = NotificationService.service.findFirst(sql_notiList, getPara("nid"));


这是完全可以实现的,而在hibernate中则无法这样实现.


//??? Record类 是什么用: 它是JFinal 自带的一个实体类,在包:package com.jfinal.plugin.activerecord.Record 下
// String sql_notiList = "select n.*, p.pname from project p,notification n where p.pid = n.pid and n.nid=" + getPara("nid");
//  
// List<Record> notiList = Db.find(sql_notiList);

0 0
原创粉丝点击