当前位置:首页 > 新闻中心 >

IBatis.net介绍

编辑:北京飞炫空间展览展示有限公司 时间:2017-09-07 13:36:28阅读次数:2
IBatis.net介绍 从上而下的理解IBatis.net这个简易的ORM框架:

1. DAL层

[csharp]

public class AccountService

{

public int TestInsertOne(Accounts account)

{ Object obj =Mapper.GetMaper.Insert("Account.sql_InsertOne", account); return (int)obj;

}

public Accounts GetAccount(int id) {

return (Accounts)Mapper.GetMaper.QueryForObject("Account.sql_selectByid", id);

}

public IList<Accounts> GetAccountList()

{ return Mapper.GetMaper.QueryForList<Accounts>("Account.sql_selectAll", null);

}

2. Model 层:

[csharp]

public class Accounts

{

public int Id { get; set; }

public string Item { get; set; }

public float Money { get; set; }

public int Month { get; set; }

public int Year { get; set; }

public int Day { get; set; }

public DateTime CreateOn { get; set; }

public string Level { get; set; }

}

3. 映射层

[html]

<?xml version="1.0" encoding="utf-8" ?><sqlMap namespace="Account" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<alias>

<!-- alias:取别名 assembly:表示类所在的文件 type:表示该类的完整的名称 -->

<typeAlias alias="Account" assembly="IBatisDemo.Model.dll" type="IBatisDemo.Model.Accounts" /> </alias>

<resultMaps>

<resultMap id="Account-result" class="Account">

<result property="Id" column="id"/>

<result property="Item" column="Item"/>

<result property="Year" column="Year"/>

<result property="Month" column="Month"/>

<result property="Day" column="Day"/>

<result property="CreateOn" column="CreateOn"/>

<result property="Level" column="Level"/>

</resultMap>

</resultMaps>

<statements>

<select id="sql_selectByid" resultMap="Account-result">

select * from Accounts

<dynamic prepend="where">

<isParameterPresent property="id" prepend="">

[id] = #id#

</isParameterPresent>

</dynamic>

</select>

<select id="sql_selectAll" resultMap="Account-result">

select * from Accounts </select>

<insert id="sql_InsertOne" parameterClass="Account">

insert into Accounts (Item,Money,Year,Month,Day,CreateOn,Level)

values (#Item#, #Money#, #Year#, #Month#, #Day#, #CreateOn#, #Level# )

<selectKey type="post" resultClass="int" property="Id">

SELECT CAST(@@IDENTITY as int) as Id

</selectKey>

</insert>

</statements>

</sqlMap>

,采集软件,站群软件

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:武汉网站建设 http://wuhan.45qun.com

上一篇:php Android 使用简介 JSON XML 区别 下一篇:最后一页

相关阅读