JadePool应用范例:查询与分页
实现民族管理很简单,可参照中国行政区划管理,这里重点介绍JadePool查询与Primefaces分页的实现。
一、参照中国行政区划管理修改模板IndexTemplate.xhtml菜单项cn_people.xhtml文件内容见附件1。
二、创建PeopleBean受管Bean
2、浏览民族记录
浏览民族记录通过使用Primefaces的p:dataTable组件实现。这里,该组件呈现peopleModel数据模型。代码如下:
附件1:cn_people.xhtml/* * PeopleBean.java * 2013-03-31 * 胡开明 */package china;import cn.jadepool.sql.Jade;import cn.jadepool.util.China;import java.util.ArrayList;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import javax.faces.application.FacesMessage;import javax.faces.bean.ManagedBean;import javax.faces.bean.SessionScoped;import javax.faces.context.FacesContext;/** * 实现中国民族管理 * * @author hkm */@ManagedBean@SessionScopedpublic class PeopleBean { private Map peopleMap = new LinkedHashMap();//民族记录 private Map peopleSelected = new LinkedHashMap();//被选择的民族记录 private List<Map> peopleList = new ArrayList();//民族记录列表,用于记录cn_people表的查询结果 private ListMapDataModel peopleModel = new ListMapDataModel(peopleList, "people_id");//民族数据模型,"people_id"是cn_people数据库表的主键名 /** * Creates a new instance of PeopleBean */ public PeopleBean() { init(); } public Map getPeopleMap() { return peopleMap; } public void setPeopleMap(Map peopleMap) { this.peopleMap = peopleMap; } public Map getPeopleSelected() { return peopleSelected; } public void setPeopleSelected(Map peopleSelected) { this.peopleSelected = peopleSelected; } public List<Map> getPeopleList() { return peopleList; } public void setPeopleList(List<Map> peopleList) { this.peopleList = peopleList; } public ListMapDataModel getPeopleModel() { return peopleModel; } public void setPeopleModel(ListMapDataModel peopleModel) { this.peopleModel = peopleModel; } /** * 初始化民族记录 */ private void init() { Jade j = new Jade(); peopleList = j.query("select * from cn_people order by people_id"); peopleModel = new ListMapDataModel(peopleList, "people_id"); j.commit(); } public void guidePeople() { China cn = new China(); List<Map> v = cn.people(); //for(Map m:v){ //System.out.println(m);//{minzu=汉族, pinxie=Han, daima=HA} //} Jade j = new Jade(); j.delete("delete from cn_people"); j.insert("cn_people", v, true);//true,自动插入主键 peopleList = j.query("select * from cn_people order by people_id"); peopleModel = new ListMapDataModel(peopleList, "people_id"); j.commit(); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("导入", "导入民族记录" + peopleList.size() + "条!")); } }