目录结构

先设计数据表结构

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', '', 'America', '');
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', '', 'America', '');
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', '', 'America', '');
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', '', 'America', '');
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', '', 'America', '');

前端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 - ) + )
.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+NHibernate3.3.3+MVC的分页效果的更多相关文章

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

    jPaginate 是一款非常精致的分页插件,提供了五种不同风格的分页效果,支持鼠标悬停翻页,快速分页功能.这款插件还提供了丰富的配置选项,你可以根据需要进行设置. 效果演示      源码下载 各个 ...

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

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  3. 基于jquery 的分页插件,前端实现假分页效果

    上次分享了一款jquery插件,现在依旧分享这个插件,不过上一次分享主要是用于regular框件,且每一页数据都是从后端获取过来的,这一次的分享主要是讲一次性获取完数据 然后手动进行分页.此需求基本上 ...

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

    这节介绍如何自定义jquery插件,实现分页效果,话不多说,先看看实现的效果: 分页插件 实现的代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTM ...

  5. 使用Jquery做分页效果

    之前写过一个PHP 的分页效果,但是今天小伙伴和我说了一个不适用后台单纯用前段的JS来写分页,整理了一下,代码如下: html: <div id="containet"> ...

  6. MVC快速分页

    .NET手记-ASP.NET MVC快速分页的实现   对于Web应用,展示List是很常见的需求,随之而来的常见的分页组件.jQuery有现成的分页组件,网上也有着大量的第三方分页组件,都能够快速实 ...

  7. MVC自定义分页

    MVC自定义分页 之前我发表了一篇MVC无刷新分页的文章,里面用的是MvcPager控件,但是那个受那个控件限制,传值只能用PagedList,各方面都受到了限制,自由度不够高,现在还是做MVC无刷新 ...

  8. 基于存储过程的MVC开源分页控件--LYB.NET.SPPager

    摘要 现在基于ASP.NET MVC的分页控件我想大家都不陌生了,百度一下一大箩筐.其中有不少精品,陕北吴旗娃杨涛大哥做的分页控件MVCPager(http://www.webdiyer.com/)算 ...

  9. JQuery对ASP.NET MVC数据进行更新删除

    以前学习ASP.NET MVC时,学习与应用,操作过数据显示,添加,编辑,更新和删除等功能. 很多方法是相通的,看自己是怎样来进行方便,快捷,高效率. 今天Insus.NET写的练习,是直接对绑定在T ...

随机推荐

  1. 04_过滤器Filter_03_多个Filter的执行顺序

    [Filter链] *在一个web应用中,可以开发编写多个Filter,这些Filter组合起来称为一个Filter链. *web服务器根据Filter在web.xml中的注册顺序,决定先调用哪个Fi ...

  2. gcc命令以及makefile文件

    (一)makefile里涉及到的gcc命令 gcc -I./inc:指定头文件寻找目录 将按照 ./inc --> /usr/include --> /usr/local/include的 ...

  3. 快速排序 javascript实现

    Quicksort(快速排序) 是由 东尼·霍尔 所发展的一种排序. 它比其他的Ο(n log n)算法更快, 因为它的内部循环(inner loop)可以在大部分的架构上很有效率地被实现出来.当然, ...

  4. python 自动化之路 day 03

    内容目录: 1. 字典 2. 集合 3. 文件处理 4. 字符编码   1. 字典操作 字典一种key - value 的数据类型,使用就像我们上学用的字典,通过笔划.字母来查对应页的详细内容. 语法 ...

  5. 【转】JSON简介以及用法代码汇总

    什么是JSON? JavaScript 对象表示法(JavaScript Object Notation). JSON是一种轻量级的数据交换格式,某个JSON格式的文件内部譬如可以长成这样: { &q ...

  6. varchar(n),nvarchar(n) 长度、性能、及所占空间分析 nvarchar(64) nvarchar(128) nvarchar(256)(转)

    varchar(n),nvarchar(n) 中的n怎么解释: nvarchar(n)最多能存n个字符,不区分中英文. varchar(n)最多能存n个字节,一个中文是两个字节. 所占空间: nvar ...

  7. 在 lamp(centos)下配置二级 域名 、虚拟主机

    1.你得拥有一个泛域名解析的顶级域名,有一个独立的IP: 2.解析二级域名,如在万网中心里,记录类型为A, 主机记录即为要配的二级域名(如:增加两个:bbs.mydomain.com 和 www.my ...

  8. python使用sqlite3

    import sqlite3 mysqldb=sqlite3.connect(r"C:\Users\Administrator\Desktop\testdb.db") mysqld ...

  9. 远程连接sql server 数据库的方法

    今天找了半天,终于解决了如何从本地连接到远程sql server服务器的方法. 1.首先确保打开远程服务器的sql server配置管理器,确保TCP/IP协议开启 2.WebConfig的连接字符格 ...

  10. NET Core 整合Autofac和Castle

    NET Core 整合Autofac和Castle 阅读目录 前言: 1.ASP.NET Core中的Autofac 2.整合Castle的DynamicProxy 3.注意事项 回到目录 前言: 除 ...