朋友炒股兩個月賺了10萬,我幫他推廣一下公眾號,把錢用來投資總比放銀行連通貨膨脹都跑不過里強, 硬核離職,在家炒股 ,這是他每天的日志,有些經驗是花錢也買不到的。
在我們平時做項目的時候與數據交互時,涉及的操作大部分為 “增、刪、改、查[又分為分頁與列表]”下面就以示例來顯示我們封裝底層后的使用實例。
一、新增與修改
新增與修改在表現上幾乎是一樣的,我們在這個示例中把新增和修改放到了一個頁面進行編輯,根據是否傳入參數來判斷是“新增”還是“修改”,那么這個頁面就要和列表頁有一個傳入值的約定,如:“添加”鏈接時我們<a href="Save.aspx">添加</a>,修改時<a href="Save.aspx?ID=<%#Eval("ID") %>">修改</a>。
圖示如下:
代碼如下:
UI層
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Save.aspx.cs" Inherits="CSharp.WebSite.Save" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 <html xmlns="http://www.w3.org/1999/xhtml"> 5 <head runat="server"> 6 <title></title> 7 </head> 8 <body> 9 <form id="form1" runat="server"> 10 員工姓名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox><br /> 11 登陸密碼:<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox><br /> 12 部門:<asp:TextBox ID="txtDepartment" runat="server"></asp:TextBox><br /> 13 職位:<asp:TextBox ID="txtPosition" runat="server"></asp:TextBox><br /> 14 <asp:Button ID="btnSubmit" runat="server" Text="確定" OnClick="btnSubmit_Click" /> 15 <asp:Button ID="btnReset" runat="server" Text="取消" OnClick="btnReset_Click" /><br /> 16 </form> 17 </body> 18 </html> 19 20 //CodeBehind 21 22 /* 23 * 24 * 創建人:李林峰 25 * 26 * 時 間:2012-07-22 27 * 28 * 描 述:員工添加與修改 29 * 30 */ 31 32 using System; 33 using System.Collections.Generic; 34 using System.Web; 35 using System.Web.UI; 36 using System.Web.UI.WebControls; 37 38 namespace CSharp.WebSite 39 { 40 /// <summary> 41 /// 員工添加與修改 42 /// </summary> 43 public partial class Save : System.Web.UI.Page 44 { 45 #region 頁面加載 46 protected void Page_Load(object sender, EventArgs e) 47 { 48 if (!Page.IsPostBack) 49 { 50 //修改時根據編號取出實體信息 51 if (!string.IsNullOrEmpty(Request.QueryString["ID"])) 52 { 53 //獲取用戶 54 GetEmployee(); 55 } 56 } 57 } 58 #endregion 59 60 #region 方法 61 /// <summary> 62 /// 獲取用戶 63 /// </summary> 64 protected void GetEmployee() 65 { 66 Model.Employee employee = new Model.Employee(); 67 employee.ID = Convert.ToInt32(Request.QueryString["ID"]); 68 employee = BLL.Employee.Get(employee); 69 this.txtName.Text = employee.Name; 70 this.txtPassword.Text = employee.Password; 71 this.txtDepartment.Text = employee.Department; 72 this.txtPosition.Text = employee.Position; 73 } 74 #endregion 75 76 #region 事件 77 /// <summary> 78 /// 提交 79 /// </summary> 80 /// <param name="sender"></param> 81 /// <param name="e"></param> 82 protected void btnSubmit_Click(object sender, EventArgs e) 83 { 84 Model.Employee employee = new Model.Employee(); 85 //如果傳入的編號不為空,說明是修改對象,則先根據編號取出對象 86 if (!string.IsNullOrEmpty(Request.QueryString["ID"])) 87 { 88 employee.ID = Convert.ToInt32(Request.QueryString["ID"]); 89 employee = BLL.Employee.Get(employee); 90 } 91 employee.Name = this.txtName.Text; 92 employee.Password = this.txtPassword.Text; 93 employee.Department = this.txtDepartment.Text; 94 employee.Position = this.txtPosition.Text; 95 //修改對象 96 if (!string.IsNullOrEmpty(Request.QueryString["ID"])) 97 { 98 if (BLL.Employee.Save(employee)) 99 MessageBox.ShowAndRedirect(this, "修改成功!", "List.aspx"); 100 else 101 MessageBox.Show(this, "修改失敗,請與管理員聯系!"); 102 } 103 else//新增 104 { 105 if (BLL.Employee.Add(employee)) 106 MessageBox.ShowAndRedirect(this, "添加成功!", "List.aspx"); 107 else 108 MessageBox.Show(this, "添加失敗,請與管理員聯系!"); 109 } 110 } 111 112 /// <summary> 113 /// 重置 114 /// </summary> 115 /// <param name="sender"></param> 116 /// <param name="e"></param> 117 protected void btnReset_Click(object sender, EventArgs e) 118 { 119 //如果控件多,可以寫個幫助類,遍歷清空 120 this.txtName.Text = ""; 121 this.txtPassword.Text = ""; 122 this.txtDepartment.Text = ""; 123 this.txtPosition.Text = ""; 124 } 125 #endregion 126 } 127 }
二、列表
列表展現用到Aspnetpager控件,在修改時向Save.aspx傳入將要修改的編號,刪除時用OnCommand事件,我們可以通過CommandName把要刪除的編號傳到服務端進行處理。
圖示如下:
代碼如下:
UI層
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="CSharp.WebSite.List" %> 2 3 <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 <title></title> 8 </head> 9 <body> 10 <form id="form1" runat="server"> 11 <table> 12 <tr> 13 <td colspan="5"> 14 <a href="Save.aspx">添加</a> 15 </td> 16 </tr> 17 <tr> 18 <td colspan="5"> 19 姓名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox><asp:Button ID="btnSearch" 20 runat="server" Text="查詢" OnClick="btnSearch_OnClick" /> 21 </td> 22 </tr> 23 <tr> 24 <td> 25 編號 26 </td> 27 <td> 28 姓名 29 </td> 30 <td> 31 部門 32 </td> 33 <td> 34 職位 35 </td> 36 <td> 37 操作 38 </td> 39 </tr> 40 <asp:Repeater ID="repList" runat="server"> 41 <ItemTemplate> 42 <tr> 43 <td> 44 <%#(Container.ItemIndex+1)+(Pager.PageSize * (Pager.CurrentPageIndex - 1)) %> 45 </td> 46 <td> 47 <%#Eval("Name") %> 48 </td> 49 <td> 50 <%#Eval("Department")%> 51 </td> 52 <td> 53 <%#Eval("Position")%> 54 </td> 55 <td> 56 <a href="Save.aspx?ID=<%#Eval("ID") %>">修改</a> 57 <asp:LinkButton ID="lbtRemove" runat="server" CommandName='<%#Eval("ID") %>' OnCommand="lbtnRemoveCommand" 58 OnClientClick="return confirm('確定刪除嗎?');" CausesValidation="False">刪除 59 </asp:LinkButton> 60 </td> 61 </tr> 62 </ItemTemplate> 63 </asp:Repeater> 64 </table> 65 <webdiyer:AspNetPager ID="Pager" CssClass="Pager" runat="server" AlwaysShow="True" 66 FirstPageText="首頁" InvalidPageIndexErrorMessage="請輸入數字頁碼!" LastPageText="末頁" 67 NextPageText="下一頁" PageIndexOutOfRangeErrorMessage="頁碼超出范圍!" PrevPageText="上一頁" 68 ShowNavigationToolTip="True" SubmitButtonText="確定" CenterCurrentPageButton="True" 69 PageIndexBoxType="TextBox" PageSize="2" ShowPageIndexBox="never" TextAfterPageIndexBox=" 頁 " 70 TextBeforePageIndexBox="轉到 " OnPageChanged="Pager_PageChanged" HorizontalAlign="NotSet" 71 CurrentPageButtonClass=""> 72 </webdiyer:AspNetPager> 73 </form> 74 </body> 75 </html> 76 77 //CodeBehind 78 79 /* 80 * 81 * 創建人:李林峰 82 * 83 * 時 間:2012-07-22 84 * 85 * 描 述:員工列表 86 * 87 */ 88 89 using System; 90 using System.Collections.Generic; 91 using System.Web; 92 using System.Web.UI; 93 using System.Web.UI.WebControls; 94 95 namespace CSharp.WebSite 96 { 97 /// <summary> 98 /// 員工列表 99 /// </summary> 100 public partial class List : System.Web.UI.Page 101 { 102 #region 頁面加載 103 /// <summary> 104 /// 面頁加載 105 /// </summary> 106 /// <param name="sender"></param> 107 /// <param name="e"></param> 108 protected void Page_Load(object sender, EventArgs e) 109 { 110 if (!Page.IsPostBack) 111 { 112 //獲取列表 113 GetList(); 114 } 115 } 116 #endregion 117 118 #region 方法 119 /// <summary> 120 /// 根據查詢條件獲取用戶列表 121 /// </summary> 122 protected void GetList() 123 { 124 int TotalCount; 125 this.repList.DataSource = BLL.Employee.GetList(this.txtName.Text, this.Pager.PageSize, Pager.PageSize * (Pager.CurrentPageIndex - 1), out TotalCount); 126 this.repList.DataBind(); 127 Pager.RecordCount = TotalCount; 128 } 129 #endregion 130 131 #region 事件 132 /// <summary> 133 /// 分頁 134 /// </summary> 135 /// <param name="sender"></param> 136 /// <param name="e"></param> 137 protected void Pager_PageChanged(object sender, EventArgs e) 138 { 139 GetList(); 140 } 141 142 /// <summary> 143 /// 查詢 144 /// </summary> 145 /// <param name="sender"></param> 146 /// <param name="e"></param> 147 protected void btnSearch_OnClick(object sender, EventArgs e) 148 { 149 GetList(); 150 } 151 152 /// <summary> 153 /// 移除 154 /// </summary> 155 /// <param name="sender"></param> 156 /// <param name="e"></param> 157 protected void lbtnRemoveCommand(object sender, CommandEventArgs e) 158 { 159 Model.Employee employee = new Model.Employee(); 160 employee.ID = Convert.ToInt32(e.CommandName); 161 if (BLL.Employee.Remove(employee)) 162 MessageBox.Show(this, "刪除成功!"); 163 else 164 MessageBox.Show(this, "刪除失敗!"); 165 //重新加載列表 166 GetList(); 167 } 168 #endregion 169 } 170 }
三、內容
根據編號取出內容
圖示如下:
代碼如下:
UI層
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Detail.aspx.cs" Inherits="CSharp.WebSite.Detail" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 <html xmlns="http://www.w3.org/1999/xhtml"> 5 <head id="Head1" runat="server"> 6 <title></title> 7 </head> 8 <body> 9 <form id="form1" runat="server"> 10 員工姓名:<asp:Literal ID="litName" runat="server"></asp:Literal><br /> 11 登陸密碼:<asp:Literal ID="litPassword" runat="server"></asp:Literal><br /> 12 部門:<asp:Literal ID="litDepartment" runat="server"></asp:Literal><br /> 13 職位:<asp:Literal ID="litPosition" runat="server"></asp:Literal> 14 </form> 15 </body> 16 </html> 17 18 //CodeBehind 19 20 /* 21 * 22 * 創建人:李林峰 23 * 24 * 時 間:2012-07-22 25 * 26 * 描 述:員工詳細 27 * 28 */ 29 30 using System; 31 using System.Collections.Generic; 32 using System.Web; 33 using System.Web.UI; 34 using System.Web.UI.WebControls; 35 36 namespace CSharp.WebSite 37 { 38 /// <summary> 39 /// 員工詳細 40 /// </summary> 41 public partial class Detail : System.Web.UI.Page 42 { 43 #region 頁面加載 44 protected void Page_Load(object sender, EventArgs e) 45 { 46 if (!Page.IsPostBack) 47 { 48 //修改時根據編號取出實體信息 49 if (!string.IsNullOrEmpty(Request.QueryString["ID"])) 50 { 51 //獲取用戶 52 GetEmployee(); 53 } 54 } 55 } 56 #endregion 57 58 #region 方法 59 /// <summary> 60 /// 獲取用戶 61 /// </summary> 62 protected void GetEmployee() 63 { 64 Model.Employee employee = new Model.Employee(); 65 employee.ID = Convert.ToInt32(Request.QueryString["ID"]); 66 employee = BLL.Employee.Get(employee); 67 this.litName.Text = employee.Name; 68 this.litPassword.Text = employee.Password; 69 this.litDepartment.Text = employee.Department; 70 this.litPosition.Text = employee.Position; 71 } 72 #endregion 73 } 74 }
四、業務邏輯層
代碼如下:
1 /* 2 * 3 * 創建人:李林峰 4 * 5 * 時 間:2012-7-22 6 * 7 * 描 述:員工 8 * 9 */ 10 11 using System.Collections.Generic; 12 13 namespace CSharp.BLL 14 { 15 /// <summary> 16 /// 員工 17 /// </summary> 18 public class Employee 19 { 20 /// <summary> 21 /// 添加實體 22 /// </summary> 23 /// <param name="employee">傳入的實體</param> 24 public static bool Add(Model.Employee employee) 25 { 26 return DAL.Employee.Add(employee); 27 } 28 29 /// <summary> 30 /// 修改實體 31 /// </summary> 32 /// <param name="employee">傳入的實體</param> 33 public static bool Save(Model.Employee employee) 34 { 35 return DAL.Employee.Save(employee); 36 } 37 38 /// <summary> 39 /// 移除實體(根據實體編號移除一條記錄) 40 /// </summary> 41 /// <param name="employee">傳入的實體,必須含有編號</param> 42 public static bool Remove(Model.Employee employee) 43 { 44 return DAL.Employee.Remove(employee); 45 } 46 47 /// <summary> 48 /// 根據編號獲取實體 49 /// </summary> 50 /// <param name="employee">傳入的實體,必須含有編號,根據編號獲取</param> 51 /// <returns>返回得到的實體</returns> 52 public static Model.Employee Get(Model.Employee employee) 53 { 54 return DAL.Employee.Get(employee); 55 } 56 57 /// <summary> 58 /// 獲取列表(無條件分頁獲取全部列表) 59 /// </summary> 60 /// <param name="PageSize">每頁的記錄數,例如:每頁顯示10條,則傳入 10 </param> 61 /// <param name="CurrentCount">當前是第幾頁</param> 62 /// <param name="TotalCount">輸出參數,返回總記錄數</param> 63 /// <returns>返回實體列表</returns> 64 public static List<Model.Employee> GetList(string Name, int PageSize, int CurrentCount, out int TotalCount) 65 { 66 return DAL.Employee.GetList(Name, PageSize, CurrentCount, out TotalCount); 67 } 68 } 69 }
五、數據操作層
代碼如下:
1 /* 2 * 3 * 創建人:李林峰 4 * 5 * 時 間:2012-7-22 6 * 7 * 描 述:員工 8 * 9 */ 10 11 using System.Data; 12 using System.Data.SqlClient; 13 using System.Collections.Generic; 14 using HZYT.DBUtility; 15 16 namespace CSharp.DAL 17 { 18 /// <summary> 19 /// 員工 20 /// </summary> 21 public class Employee 22 { 23 /// <summary> 24 /// 添加實體 25 /// </summary> 26 /// <param name="employee">傳入的實體</param> 27 /// <returns>操作數據庫時返回的操作行數,如果大於 "0" 則返回 true 否則返回 false</returns> 28 public static bool Add(CSharp.Model.Employee employee) 29 { 30 return ORM.Add(employee, Constant.ASSEMBLYPATH, Constant.CONNSTRING); 31 } 32 33 /// <summary> 34 /// 修改實體 35 /// </summary> 36 /// <param name="employee">傳入的實體</param> 37 /// <returns>操作數據庫時返回的操作行數,如果大於 "0" 則返回 true 否則返回 false</returns> 38 public static bool Save(Model.Employee employee) 39 { 40 return ORM.Save(employee, Constant.ASSEMBLYPATH, Constant.CONNSTRING); 41 } 42 43 /// <summary> 44 /// 移除實體(根據實體編號移除一條記錄) 45 /// </summary> 46 /// <param name="employee">傳入的實體,必須含有編號</param> 47 /// <returns>操作數據庫時返回的操作行數,如果大於 "0" 則返回 true 否則返回 false</returns> 48 public static bool Remove(Model.Employee employee) 49 { 50 return ORM.Remove(employee, Constant.ASSEMBLYPATH, Constant.CONNSTRING); 51 } 52 53 /// <summary> 54 /// 移除實體(根據實體列表移除多條記錄) 55 /// </summary> 56 /// <param name="listEmployee">傳入的實體列表,必須都含有編號</param> 57 /// <returns>操作數據庫時返回的操作行數,如果大於 "0" 則返回 true 否則返回 false</returns> 58 public static bool Remove(List<Model.Employee> listEmployee) 59 { 60 List<object> listObject = new List<object>(); 61 foreach (Model.Employee model in listEmployee) 62 { 63 listObject.Add(model); 64 } 65 return ORM.Remove(listObject, Constant.ASSEMBLYPATH, Constant.CONNSTRING); 66 } 67 68 /// <summary> 69 /// 根據編號獲取實體 70 /// </summary> 71 /// <param name="employee">傳入的實體,必須含有編號,根據編號獲取</param> 72 /// <returns>返回得到的實體</returns> 73 public static Model.Employee Get(Model.Employee employee) 74 { 75 return (Model.Employee)ORM.Get(employee, Constant.ASSEMBLYPATH, Constant.CONNSTRING); 76 } 77 78 /// <summary> 79 /// 獲取列表(無條件獲取全部列表) 80 /// </summary> 81 /// <returns>返回實體列表</returns> 82 public static List<Model.Employee> GetList() 83 { 84 List<Model.Employee> returnList = new List<Model.Employee>(); 85 List<object> tempList = ORM.GetList(new Model.Employee(), Constant.ASSEMBLYPATH, Constant.CONNSTRING); 86 return GetList(tempList); 87 } 88 89 /// <summary> 90 /// 獲取列表(無條件分頁獲取全部列表) 91 /// </summary> 92 /// <param name="PageSize">每頁的記錄數,例如:每頁顯示10條,則傳入 10 </param> 93 /// <param name="CurrentCount">當前是第幾頁</param> 94 /// <param name="TotalCount">輸出參數,返回總記錄數</param> 95 /// <returns>返回實體列表</returns> 96 public static List<Model.Employee> GetList(int PageSize, int CurrentCount, out int TotalCount) 97 { 98 List<Model.Employee> returnList = new List<Model.Employee>(); 99 List<object> tempList = ORM.GetList(new Model.Employee(), PageSize, CurrentCount, out TotalCount, Constant.ASSEMBLYPATH, Constant.CONNSTRING); 100 return GetList(tempList); 101 } 102 103 /// <summary> 104 /// 獲取列表(無條件分頁獲取全部列表) 105 /// </summary> 106 /// <param name="PageSize">每頁的記錄數,例如:每頁顯示10條,則傳入 10 </param> 107 /// <param name="CurrentCount">當前是第幾頁</param> 108 /// <param name="TotalCount">輸出參數,返回總記錄數</param> 109 /// <returns>返回實體列表</returns> 110 public static List<Model.Employee> GetList(string Name, int PageSize, int CurrentCount, out int TotalCount) 111 { 112 string WHERE = " 1=1 "; 113 if (Name.Trim() != string.Empty) 114 { 115 WHERE += " AND Name LIKE '%" + Name + "%'"; 116 } 117 return GetList(PageSize, CurrentCount, WHERE, out TotalCount); 118 } 119 120 #region 獲取列表[私有方法] 121 /// <summary> 122 /// 獲取列表(根據查詢條件獲取全部列表) 123 /// </summary> 124 /// <param name="Where">SQL拼接的查詢條件字條串,例如: " ID < 100 " </param> 125 /// <returns>返回實體列表</returns> 126 private static List<Model.Employee> GetList(string Where) 127 { 128 List<Model.Employee> returnList = new List<Model.Employee>(); 129 List<object> tempList = ORM.GetList(new Model.Employee(), Where, Constant.ASSEMBLYPATH, Constant.CONNSTRING); 130 return GetList(tempList); 131 } 132 133 /// <summary> 134 /// 獲取列表(無條件分頁獲取全部列表) 135 /// </summary> 136 /// <param name="PageSize">每頁的記錄數,例如:每頁顯示10條,則傳入 10 </param> 137 /// <param name="CurrentCount">當前是第幾頁</param> 138 /// <param name="Where">SQL拼接的查詢條件字條串,例如: " ID < 100 " </param> 139 /// <param name="TotalCount">輸出參數,返回總記錄數</param> 140 /// <returns>返回實體列表</returns> 141 private static List<Model.Employee> GetList(int PageSize, int CurrentCount, string Where, out int TotalCount) 142 { 143 List<Model.Employee> returnList = new List<Model.Employee>(); 144 List<object> tempList = ORM.GetList(new Model.Employee(), PageSize, CurrentCount, Where, out TotalCount, Constant.ASSEMBLYPATH, Constant.CONNSTRING); 145 return GetList(tempList); 146 } 147 #endregion 148 149 #region 類型轉換[私有方法] 150 /// <summary> 151 /// 將對象類型轉換成為Employee類型 152 /// </summary> 153 /// <param name="objList"></param> 154 /// <returns>返回實體列表</returns> 155 private static List<Model.Employee> GetList(List<object> objList) 156 { 157 List<Model.Employee> returnList = new List<Model.Employee>(); 158 foreach (object tempobject in objList) 159 { 160 returnList.Add((Model.Employee)tempobject); 161 } 162 return returnList; 163 } 164 #endregion 165 } 166 }
六、實體層
實體層有兩個類Employee.cs與EmployeeMapping.cs,一個用來存儲在各個層之間傳輸的數據信息,一個來描述實體與數據庫的對應關系。
代碼如下:
1 /* 2 * 3 * 創建人:李林峰 4 * 5 * 時 間:2012-7-122 6 * 7 * 描 述:員工 8 * 9 */ 10 11 using System; 12 13 namespace CSharp.Model 14 { 15 /// <summary> 16 /// 員工 17 /// </summary> 18 public class Employee 19 { 20 public int ID { get; set; } //編號 21 public string Name { get; set; } //姓名 22 public string Password { get; set; } //密碼 23 public string Department { get; set; } //部門 24 public string Position { get; set; } //職位 25 } 26 } 27 28 29 /* 30 * 31 * 創建人:李林峰 32 * 33 * 時 間:2012-7-22 34 * 35 * 描 述:員工映射 36 * 37 */ 38 39 using System.Collections.Generic; 40 41 namespace CSharp.Model 42 { 43 /// <summary> 44 /// 員工映射 45 /// </summary> 46 public class EmployeeMapping 47 { 48 /// <summary> 49 /// 表名稱 50 /// </summary> 51 public static string GetTableName() 52 { 53 return "Employee"; 54 } 55 56 /// <summary> 57 /// 主鍵名稱 58 /// </summary> 59 public static Dictionary<string, string> GetIdentityMapping() 60 { 61 Dictionary<string, string> Identity = new Dictionary<string, string>(); 62 Identity.Add("ID", "ID"); 63 return Identity; 64 } 65 66 /// <summary> 67 /// 基礎字段 68 /// </summary> 69 public static Dictionary<string, string> GetBaseFieldMapping() 70 { 71 Dictionary<string, string> BaseField = new Dictionary<string, string>(); 72 BaseField.Add("Name", "Name"); 73 BaseField.Add("Password", "Password"); 74 BaseField.Add("Department", "Department"); 75 BaseField.Add("Position", "Position"); 76 return BaseField; 77 } 78 } 79 }
七、總結
通過上面的實例我們可以看出惟一不同之處在於我們的數據操作層只用了很少的SQL就完成了“增、刪、改、查”的四項操作功能,而在實體層里我們多了一個實例與數據庫的映射關系類。這樣我們在開發中配上代碼生成工具就很“快速、簡潔”的完成了工作。
八、代碼下載