iBATIS.NET 学习笔记(五)
生活随笔
收集整理的這篇文章主要介紹了
iBATIS.NET 学习笔记(五)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
用iBATIS.NET簡(jiǎn)單查詢數(shù)據(jù)。
項(xiàng)目目錄結(jié)構(gòu):
新建類Mapper.cs
//*公司:
//*作者:YK
//*模塊:IbatisNet.Example
//*功能:
//*創(chuàng)建日期:
//*修改日期:
//***********************************************************
using?System;
using?IBatisNet.Common.Utilities;
using?IBatisNet.DataMapper;
using?IBatisNet.DataAccess;
using?IBatisNet.DataAccess.Configuration;
using?IBatisNet.DataMapper.Configuration;
namespace?IbatisNet.Example
{
????/**////?<summary>
????///?Mapper?的摘要說(shuō)明。
????///?</summary>
????public?class?Mapper
????{
????????private?static?volatile?SqlMapper?_mapper?=?null;
????????protected?static?void?Configure?(object?obj)
????????{
????????????_mapper?=?(SqlMapper)?obj;
????????}
????????protected?static?void?InitMapper()
????????{???
????????????ConfigureHandler?handler?=?new?ConfigureHandler(Configure);
????????????DomSqlMapBuilder?builder?=?new?DomSqlMapBuilder();
????????????_mapper?=?builder.ConfigureAndWatch(handler);
????????}
????????public?static?SqlMapper?Instance()
????????{
????????????if?(_mapper?==?null)
????????????{
????????????????lock?(typeof?(SqlMapper))
????????????????{
????????????????????if?(_mapper?==?null)?//?double-check
????????????????????????InitMapper();
????????????????}
????????????}
????????????return?_mapper;
????????}
????????public?static?SqlMapper?Get()
????????{
????????????return?Instance();
????????}
????}
????
}
新建Web頁(yè)面,Test1.aspx
<%@?Page?language="c#"?Codebehind="Test1.aspx.cs"?AutoEventWireup="false"?Inherits="IbatisNet.Example.Test1"?%>
<!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.0?Transitional//EN"?>
<HTML>
????<HEAD>
????????<title>Test1</title>
????????<meta?name="GENERATOR"?Content="Microsoft?Visual?Studio?.NET?7.1">
????????<meta?name="CODE_LANGUAGE"?Content="C#">
????????<meta?name="vs_defaultClientScript"?content="JavaScript">
????????<meta?name="vs_targetSchema"?content="http://schemas.microsoft.com/intellisense/ie5">
????</HEAD>
????<body>
????????<form?id="Form1"?method="post"?runat="server">
????????????<asp:DataGrid?id="dgList"?runat="server"?BorderColor="#E7E7FF"?BorderStyle="None"?BorderWidth="1px"
????????????????BackColor="White"?CellPadding="3"?GridLines="Horizontal"?AllowPaging="True"?AutoGenerateColumns="False">
????????????????<SelectedItemStyle?Font-Bold="True"?ForeColor="#F7F7F7"?BackColor="#738A9C"></SelectedItemStyle>
????????????????<AlternatingItemStyle?BackColor="#F7F7F7"></AlternatingItemStyle>
????????????????<ItemStyle?ForeColor="#4A3C8C"?BackColor="#E7E7FF"></ItemStyle>
????????????????<HeaderStyle?Font-Bold="True"?ForeColor="#F7F7F7"?BackColor="#4A3C8C"></HeaderStyle>
????????????????<FooterStyle?ForeColor="#4A3C8C"?BackColor="#B5C7DE"></FooterStyle>
????????????????<Columns>
????????????????????<asp:BoundColumn?DataField="CustomerID"?HeaderText="CustomerID"></asp:BoundColumn>
????????????????????<asp:BoundColumn?DataField="CompanyName"?HeaderText="CompanyName"></asp:BoundColumn>
????????????????????<asp:BoundColumn?DataField="Address"?HeaderText="Address"></asp:BoundColumn>
????????????????????<asp:BoundColumn?DataField="City"?HeaderText="City"></asp:BoundColumn>
????????????????????<asp:BoundColumn?DataField="Phone"?HeaderText="Phone"></asp:BoundColumn>
????????????????????<asp:BoundColumn?DataField="Fax"?HeaderText="Fax"></asp:BoundColumn>
????????????????</Columns>
????????????????<PagerStyle?HorizontalAlign="Right"?ForeColor="#4A3C8C"?BackColor="#E7E7FF"></PagerStyle>
????????????</asp:DataGrid>
????????</form>
????</body>
</HTML>
Test1.aspx.cs
//***********************************************************
//*公司:
//*作者:YK
//*模塊:Test1
//*功能:
//*創(chuàng)建日期:
//*修改日期:
//***********************************************************
using?System;
using?System.Collections;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Web;
using?System.Web.SessionState;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Web.UI.HtmlControls;
using?IBatisNet.Common;
using?IBatisNet.Common.Utilities;
using?IBatisNet.DataMapper;
using?IBatisNet.DataAccess;
namespace?IbatisNet.Example
{
????/**////?<summary>
????///?Test1?的摘要說(shuō)明。
????///?</summary>
????public?class?Test1?:?System.Web.UI.Page
????{
????????protected?System.Web.UI.WebControls.DataGrid?dgList;
????
????????private?void?Page_Load(object?sender,?System.EventArgs?e)
????????{
????????????//?在此處放置用戶代碼以初始化頁(yè)面
????????????if(!Page.IsPostBack)
????????????{
????????????
????????????????this.GetData();
????????????}
????????}
????????Web?窗體設(shè)計(jì)器生成的代碼#region?Web?窗體設(shè)計(jì)器生成的代碼
????????override?protected?void?OnInit(EventArgs?e)
????????{
????????????//
????????????//?CODEGEN:?該調(diào)用是?ASP.NET?Web?窗體設(shè)計(jì)器所必需的。
????????????//
????????????InitializeComponent();
????????????base.OnInit(e);
????????}
????????
????????/**////?<summary>
????????///?設(shè)計(jì)器支持所需的方法?-?不要使用代碼編輯器修改
????????///?此方法的內(nèi)容。
????????///?</summary>
????????private?void?InitializeComponent()
????????{????
????????????this.dgList.PageIndexChanged?+=?new?System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgList_PageIndexChanged);
????????????this.Load?+=?new?System.EventHandler(this.Page_Load);
????????}
????????#endregion
????????private?void?GetData()
????????{
????????????this.dgList.DataSource?=IbatisNet.Example.Mapper.Instance().QueryForList("GetAllCustomers",null);
????????????this.dgList.DataBind();
????????}
????????private?void?dgList_PageIndexChanged(object?source,?System.Web.UI.WebControls.DataGridPageChangedEventArgs?e)
????????{
????????????this.dgList.CurrentPageIndex?=?e.NewPageIndex;
????????????this.GetData();
????????}
????}
}
名程為“GetAllCustomers"的查詢,在Maps/Customers.xml中設(shè)置。
運(yùn)行通過(guò)。
轉(zhuǎn)載于:https://www.cnblogs.com/yknb/archive/2006/07/19/454921.html
總結(jié)
以上是生活随笔為你收集整理的iBATIS.NET 学习笔记(五)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python常用的装饰器库_Python
- 下一篇: android R vendor.boo