首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

JadePool施用范例:查询与分页

2013-04-05 
JadePool应用范例:查询与分页实现民族管理很简单,可参照中国行政区划管理,这里重点介绍JadePool查询与Prim

JadePool应用范例:查询与分页

实现民族管理很简单,可参照中国行政区划管理,这里重点介绍JadePool查询与Primefaces分页的实现

一、参照中国行政区划管理修改模板IndexTemplate.xhtml菜单项
        将<p:menuitem value="民族" url="#" />修改为<p:menuitem value="中国民族" outcome="cn_people" />;
        创建cn_people.xhtml文件,因为使用的outcome属性,如果该文件不存在,则运行异常。

        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() + "条!"));    }    }

热点排行