jquery+NHibernate的分页效果

目录结构

先设计数据表结构

DROP SEQUENCE BDLLY_2V.SEQ_CUSTOMER;

CREATE SEQUENCE BDLLY_2V.SEQ_CUSTOMER
  START WITH 6
  MAXVALUE 999999999999999999999999999
  MINVALUE 0
  NOCYCLE
  NOCACHE
  NOORDER;

DROP TABLE BDLLY_2V.CUSTOMER CASCADE CONSTRAINTS;

CREATE TABLE Customer
(
  CustomerId INTEGER,
  CompanyName VARCHAR2(50),
  ContactName VARCHAR2(50),
  ContactTitle VARCHAR2(50),
  Address VARCHAR2(50),
  City VARCHAR2(30),
  Region VARCHAR2(20),
  PostalCode VARCHAR2(10),
  Country VARCHAR2(50),
  Phone VARCHAR2(15)
);

Insert into BDLLY_2V.CUSTOMER
   (CUSTOMERID, COMPANYNAME, CONTACTNAME, CONTACTTITLE, ADDRESS,
    CITY, REGION, POSTALCODE, COUNTRY, PHONE)
 Values
   (1, ‘ Apple Inc.‘, ‘Steve P.(aul) Jobs‘, ‘iPhone Change the world‘, ‘America in San Francisco, California‘,
    ‘San Francisco‘, ‘Buddhism‘, ‘10086‘, ‘America‘, ‘15810708032‘);
Insert into BDLLY_2V.CUSTOMER
   (CUSTOMERID, COMPANYNAME, CONTACTNAME, CONTACTTITLE, ADDRESS,
    CITY, REGION, POSTALCODE, COUNTRY, PHONE)
 Values
   (2, ‘Microsoft Inc.‘, ‘Bill Gates‘, ‘Personal Computer‘, ‘Redmond, Washington America‘,
    ‘Washington‘, ‘Christianism‘, ‘10001‘, ‘America‘, ‘13822334423‘);
Insert into BDLLY_2V.CUSTOMER
   (CUSTOMERID, COMPANYNAME, CONTACTNAME, CONTACTTITLE, ADDRESS,
    CITY, REGION, POSTALCODE, COUNTRY, PHONE)
 Values
   (3, ‘Google‘, ‘Lawrence Edward Page‘, ‘Google Earth‘, ‘Mountain view, Santa Clara County, California USA‘,
    ‘County of Santa Clara‘, ‘none‘, ‘10032‘, ‘America‘, ‘18612446481‘);
Insert into BDLLY_2V.CUSTOMER
   (CUSTOMERID, COMPANYNAME, CONTACTNAME, CONTACTTITLE, ADDRESS,
    CITY, REGION, POSTALCODE, COUNTRY, PHONE)
 Values
   (4, ‘Twitter‘, ‘Evan Williams‘, ‘what happening‘, ‘America in San Francisco, California‘,
    ‘San Francisco‘, ‘none‘, ‘10086‘, ‘America‘, ‘15810708032‘);
Insert into BDLLY_2V.CUSTOMER
   (CUSTOMERID, COMPANYNAME, CONTACTNAME, CONTACTTITLE, ADDRESS,
    CITY, REGION, POSTALCODE, COUNTRY, PHONE)
 Values
   (5, ‘Facebook‘, ‘Mark Elliot Zuckerberg‘, ‘ Done is better than perfect.‘, ‘Palo Alto, California, USA‘,
    ‘alo Alto‘, ‘none‘, ‘10021‘, ‘America‘, ‘18612446481‘);

前端jquery

引用

<script src="../../Scripts/jquery-1.8.2.min.js"></script>
<script src="../../Scripts/jquery-pager.js" type="text/javascript"></script>
<link href="../../Scripts/pager.css" rel="stylesheet" type="text/css" />

<script lang="ja" type="text/javascript">
        //PageIndex当前页码
        //PageCount当前页数
        function init(PageIndex, PageCount) {
            var receive_url = "/Customer/GetMerchant?PageIndex=" + PageIndex + "&PageCount=" + PageCount;
            $.ajax({
                type: "GET",
                url: receive_url,
                cache: "false",
                success: function (data) {
                    data = eval(data);
                    //循环表格
                    $("tbody").html("");
                    var html = "";
                    for (var i = 0; i < data.length; i++) {
                        var json = null;
                        json = data[i];
                        var customId = json.CustomerId;
                        var companyName = json.CompanyName;
                        var contactName = json.ContactName;
                        var contactTitle = json.ContactTitle;
                        var address = json.Address;
                        var city = json.City;
                        var region = json.Region;
                        var postalCode = json.PostalCode;
                        var country = json.Country;
                        var phone = json.Phone;
                        html += "<tr><td>" + customId + "</td><td>" + companyName + "</td><td>" + contactName + "</td><td>" + contactTitle + "</td><td>" + address + "</td><td>" + city + "</td><td>" + region + "</td><td>" + postalCode + "</td><td>" + country + "</td><td>" + phone + "</td></tr>";
                    }
                    $("tbody").append(html);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("程序异常!");
                }
            });
        };

        $(document).ready(function () {
            //得到页面数据总数
            var result = null;
            $.ajax({
                type: "POST",
                url: "/Customer/GetPageCount",
                cache: "false",
                async: false,
                success: function (data) {
                    result = eval(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("程序异常!");
                }
            });
            initPager(result, 1);
        });

        //RecordCount[总记录数] PageIndex[当前页码]
        function initPager(RecordCount, PageIndex) {
            $("#page-bottom").setPager({
                RecordCount: RecordCount,
                PageIndex: PageIndex,
                buttonClick: function (RecordCount, PageIndex) {
                    initPager(RecordCount, PageIndex);
                }
            });
            //分页同时更新数据源
            init(PageIndex, 20);
        };

    </script>

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
This template was written to work with NHibernate.Test.
Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
for your own use before compile tests in VisualStudio.
-->
<!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory name="NHibernateUI">
        <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
        <property name="connection.connection_string">
            User ID=bdlly_2v;Password=gmgl;Data Source=glxt
        </property>
        <property name="show_sql">false</property>
        <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
        <property name="query.substitutions">true 1, false 0, yes ‘Y‘, no ‘N‘</property>
    <!--添加下面这行代码,除此之外,其它都不用改动,当然,你也可以修改上面的数据库链接字符串-->
    <mapping assembly="NHibernate.Domain"/>
    </session-factory>
</hibernate-configuration>

Entity:

namespace NHibernate.Domain
{

    public class Customer
    {
        public virtual int CustomerId { get; set; }
        public virtual string CompanyName { get; set; }
        public virtual string ContactName { get; set; }
        public virtual string ContactTitle { get; set; }
        public virtual string Address { get; set; }
        public virtual string City { get; set; }
        public virtual string Region { get; set; }
        public virtual string PostalCode { get; set; }
        public virtual string Country { get; set; }
        public virtual string Phone { get; set; }
    }}

Mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Domain" namespace="NHibernate.Domain">
  <class name="NHibernate.Domain.Customer,NHibernate.Domain" table="Customer">
    <id name="CustomerId" column="CustomerId" type="int" unsaved-value="0">
      <generator  class= "sequence">
        <param  name= "sequence">SEQ_CUSTOMER</param>
      </generator>
    </id>
    <property name="CompanyName" column="CompanyName" type="string"  />
    <property name="ContactName" column="ContactName" type="string"  />
    <property name="ContactTitle" column="ContactTitle" type="string"  />
    <property name="Address" column="Address" type="string"  />
    <property name="City" column="City" type="string"  />
    <property name="Region" column="Region" type="string"  />
    <property name="PostalCode" column="PostalCode" type="string"  />
    <property name="Country" column="Country" type="string"  />
    <property name="Phone" column="Phone" type="string"  />

  </class>
</hibernate-mapping>

NHibernate.DataPortal:

namespace NHibernate.DataPortal
{
    public class CustomerOperator
    {
        private NHibernateHelper nhibernateHelper = new NHibernateHelper();

        protected ISession Session { get; set; }

        /// <summary>
        /// 打开Session
        /// </summary>
        public CustomerOperator()
        {
            this.Session = nhibernateHelper.GetSession();
        }
        /// <summary>
        /// 构造session
        /// </summary>
        /// <param name="session"></param>
        public CustomerOperator(ISession session)
        {
            this.Session = session;
        }

        /// <summary>
        /// 查询客户并返回所有的信息
        /// </summary>
        /// <returns></returns>
        public IList<Customer> GetCunstomers(int pageIndex, int pageCount)
        {
            IList<Customer> list = (IList<Customer>)Session.CreateQuery("FROM Customer")
            .SetFirstResult(pageCount * (pageIndex - 1) + 1)
            .SetMaxResults(pageCount)
            .List<Customer>();
            return list;
        }
        /// <summary>
        /// 查询记录数
        /// </summary>
        /// <returns></returns>
        public Single GetCount()
        {
            IQuery q = Session.CreateQuery(@"SELECT t FROM Customer t");
            return Convert.ToSingle(q.List().Count);
        }

    }
}

Controllers:

namespace NHibernateUI.Controllers
{
    public class CustomerController : Controller
    {
        //
        // GET: /Customer/

        public ActionResult Merchant()
        {
            return View();
        }
        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <returns></returns>
        public ActionResult GetMerchant()
        {
            //请求当前页码和当前页数
            int pageIndex = Convert.ToInt32(Request.Params.Get("PageIndex"));
            int pageCount = Convert.ToInt32(Request.Params.Get("PageCount"));

            CustomerOperator oper = new CustomerOperator();
            IList<Customer> list = oper.GetCunstomers(pageIndex,pageCount);

            return Json(list, JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetPageCount()
        {
            CustomerOperator oper=new CustomerOperator();
            Single s = oper.GetCount();
            return Json(s, JsonRequestBehavior.AllowGet);
        }

    }
}

jquery+NHibernate的分页效果,布布扣,bubuko.com

时间: 2024-11-03 05:43:25

jquery+NHibernate的分页效果的相关文章

jquery+json实现分页效果

son作为一种轻量级的数据交换格式,由于其传输数据格式的方便性,今天偶然想将其应用于分页实现,分页做为web开发一个长久的话题,其应用的高效与重要性就不多说了本文主要技术:反射机制,Json数据格式,jquery为了应用的通用性,首先要根据反射机制,能将要返回的任意类型的结果对象转化成Json类型的格式. public static String toJSON(Object obj) { HashMap map = new HashMap(); Class c = obj.getClass();

5种风格的 jQuery 分页效果【附代码】

5种风格的 jQuery 分页效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>jQuery Pagination - jPaginate</title> <meta http-equi

jquery自定义插件实现分页效果

这节介绍如何自定义jquery插件,实现分页效果,话不多说,先看看实现的效果: 分页插件 实现的代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta charset="utf-8"> <title>page t

jQuery模拟无刷新分页效果

<html> <head> <title>jQuery模拟无刷新分页效果|河北苗木|河北金梆子锅炉</title> <script src="/images/jquery-1.4.2.min.js" type="text/javascript"></script> <style type="text/css"> body { font-size:12px; col

分享5种风格的 jQuery 分页效果【附代码】

jPaginate 是一款非常精致的分页插件,提供了五种不同风格的分页效果,支持鼠标悬停翻页,快速分页功能.这款插件还提供了丰富的配置选项,你可以根据需要进行设置. 效果演示      源码下载 各个效果的使用示例代码: $(function() { $("#demo1").paginate({ count : 100, start : 1, display : 8, border : true, border_color : '#fff', text_color : '#fff',

基于jquery的ajax分页插件(demo+源码)

前几天打开自己的博客园主页,无意间发现自己的园龄竟然有4年之久了.可是看自己的博客列表却是空空如也,其实之前也有写过,但是一直没发布(然而好像并没有什么卵用).刚开始学习编程时就接触到博客园,且在博客园学习了很多的知识,看过很多人的分享.说来也惭愧,自己没能为园友们分享自己的所学所得(毕竟水平比较差). 过去的一年也是辗转了几个城市换了几份工作(注定本命年不太平?).八月份来到现在所在的公司(OTA行业),公司是做互联网的,所以可能大家的前端都屌屌的?之前一直从事.NET开发(现在在这边也是),

推荐20款基于 jQuery &amp; CSS 的文本效果插件

jQuery 和 CSS 可以说是设计和开发行业的一次革命.这一切如此简单,快捷的一站式服务.jQuery 允许你在你的网页中添加一些真正令人惊叹的东西而不用付出很大的努力,要感谢那些优秀的 jQuery 插件. 所以今天我们将展示一些很酷的文本效果插件,将帮助你为你的 Web 页面创建一些很酷的和动态的东西.这里是20个基于 jQuery & CSS 的文本效果插件. 您可能感兴趣的相关文章 12款经典的白富美型 jQuery 图片轮播插件 让网站动起来!12款优秀的 jQuery 动画插件

JS实现分页效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

spring mvc +HTML5实现移动端底部上滑异步加载更多内容分页效果

由于手机的携带的方便性和手机的越来越智能和移动网速越来越快,手机已经充斥着人们的生活.随着手机的流行, 移动应用也快速的火了起来比如微商城.手机网页.移动APP等等.既然移动应用这么火,我们今天来讲一下怎样实现在移 动网页中动态加载数据,那么我们怎么实现呢,是像pc网页那样,有个上一页和下一页还是其它的方式. 其实像pc网页那样上一页和下一页肯定不行的,手机屏幕很小,不好点击同时用户体验很差,今天来给大家介绍使用 spring mvc +HTML5实现移动端底部上滑异步加载更多内容分页效果的方式