iBatis使用小例

步骤:

1、map(xml文件)

2.实体类

3、DAO接口类

4.DAO的接口实现类

5、service接口类

6、service的接口实现类

7、castle-dao.config配置文件

8、SqlMap.config配置文件

9、调用就OK了

小例:

xml文件

	<statements>

	<select id="HaierPageView_GetCount" resultClass="System.Int32">
      SELECT count(*) FROM [IOMTrackData2012FirstHalfYear].[dbo].[HaierPageView]
    </select>
    <select id="HaierPageView_InitialByWhere" parameterClass="String" resultMap="HaierPageView_FullResultMap">
		SELECT top 50 *
		FROM [IOMTrackData2012FirstHalfYear].[dbo].[HaierPageView] as A
		WHERE  $value$
	</select>
    <select id="HaierPageView_FindAll" resultMap="HaierPageView_FullResultMap">
		SELECT top 50 A.*
		FROM [IOMTrackData2012FirstHalfYear].[dbo].[HaierPageView] as A LEFT JOIN (SELECT DISTINCT [Page_ID],[ProductID] FROM [IOMTrackData2012FirstHalfYear].[dbo].[HaierTagView])  as B ON A.Page_ID=B.Page_ID
	</select>
    <select id="HaierPageView_FindAllByWhere" parameterClass="String" resultMap="HaierPageView_FullResultMap" extends="HaierPageView_FindAll">
      WHERE  $value$
    </select>
    <select id="HaierPageView_Attitude" resultClass="System.Int32">
      SELECT COUNT(*) FROM [IOMTrackData2012FirstHalfYear].[dbo].[HaierPageView] where $values$
    </select>
	<!--自定义查询-SQL语句$SQLstatement$->
	<select id="HaierPageView_FindAllByCustomWhere"  parameterClass="System.Collections.IDictionary" resultMap="HaierPageView_FullResultMap">
		SELECT top 50 A.*
		FROM [IOMTrackData2012FirstHalfYear].[dbo].[HaierPageView] as A LEFT JOIN
		(SELECT DISTINCT [Page_ID] FROM [IOMTrackData2012FirstHalfYear].[dbo].[HaierTagView] WHERE 1=1 $HaierTagViewWhere$)  as B
		ON A.Page_ID=B.Page_ID
		WHERE 1=1 $HaierPageViewWhere$
	</select>
	</statements>


 XML文件:调用存储过程

<parameterMaps>
		<parameterMap id="IWTBrandTag_para_getFirstTagIdsByTagName" class="System.Collections.IDictionary">
			<parameter property="TagName" column="TagName" dbType="NVarChar"/>
			<parameter property="BrandID" column="BrandID" dbType="Int"/>
		</parameterMap>
		<parameterMap id="IWTBrandTag_para_getNorepeatSecondTagNamesByFirstTagName" class="System.Collections.IDictionary">
			<parameter property="TagName" column="TagName" dbType="NVarChar"/>
			<parameter property="BrandID" column="BrandID" dbType="Int"/>
		</parameterMap>
	</parameterMaps>	
	<statements>
		<procedure id="IWTBrandTag_getFirstTagIdsByTagName" parameterMap="IWTBrandTag_para_getFirstTagIdsByTagName" resultClass="System.String">
			[IOMTrackData2012FirstHalfYear].[dbo].[getFirstTagIdsByTagName]
		</procedure>
		<procedure id="IWTBrandTag_getNorepeatSecondTagNamesByFirstTagName" parameterMap="IWTBrandTag_para_getNorepeatSecondTagNamesByFirstTagName" resultClass="System.String">
			[IOMTrackData2012FirstHalfYear].[dbo].[getNorepeatSecondTagNamesByFirstTagName]
		</procedure>


 DAO接口类

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Iwom.Haier.Model;

namespace Iwom.Haier.DAO.Intf
{
    public partial interface IHaierPageViewDao
    {
        /// <summary>Finds all IWTBrandProduct instances.</summary>
        IList<HaierPageView> FindAllByWhere(string where);
        /// <summary>Finds all IWTBrandProduct instances.</summary>
        IList<HaierPageView> InitialByWhere(string where);
        /// <summary>Finds all IWTBrandProduct instances.</summary>
        IList<HaierPageView> FindAllByCustomWhere(Hashtable ht);
        int HaierPageView_Attitude(string where);
    }
}

DA0接口实现类


//==============================================================================
//	CAUTION: This file is generated by IBatisNetGen.DaoImpl.cst at 2012/8/1 15:07:34
//				Any manual editing will be lost in re-generation.
//==============================================================================
using System;
using System.Collections.Generic;
using System.Text;
using IBatisNet.DataMapper;
using Iwom.Haier.Model;
using Iwom.Haier.DAO.Intf;
using Iwom.Haier.DAO;

namespace Iwom.Haier.DAO.Impl
{
    public partial class HaierPageViewDao : BaseDAO, IHaierPageViewDao
    {
        #region IHaierPageViewDao 成员

        public IList<HaierPageView> FindAllByWhere(string where)
        {
            String stmtId = "HaierPageView_FindAllByWhere";
            IList<HaierPageView> result = Instance.QueryForList<HaierPageView>(stmtId, where);
            return result;
        }

        #endregion

        #region IHaierPageViewDao 成员

        #region IHaierPageViewDao 成员


        public IList<HaierPageView> InitialByWhere(string where)
        {
            String stmtId = "HaierPageView_InitialByWhere";
            IList<HaierPageView> result = Instance.QueryForList<HaierPageView>(stmtId, where);
            return result;
        }

        #endregion
        public int HaierPageView_Attitude(string where)
        {
            return Instance.QueryForObject<int>("HaierPageView_Attitude", where);
           
        }
    

        #endregion

        #region IHaierPageViewDao 成员


        public IList<HaierPageView> FindAllByCustomWhere(System.Collections.Hashtable ht)
        {
            String stmtId = "HaierPageView_FindAllByCustomWhere";
            IList<HaierPageView> result = Instance.QueryForList<HaierPageView>(stmtId, ht);
            return result;
        }

        #endregion
    }
}


service接口类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Iwom.Haier.Model;

namespace Iwom.Haier.Service.Intf
{
    public partial interface IHaierPageViewService
    {
        /// <summary>Finds all IWTBrandProduct instances.</summary>
        IList<HaierPageView> FindAllByWhere(string where);
        /// <summary>Finds all IWTBrandProduct instances.</summary>
        IList<HaierPageView> InitialByWhere(string where);
        int HaierPageView_Attitude(string where);
    }
}


service的接口实现类

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Iwom.Haier.Service.Intf;
using Iwom.Haier.DAO.Intf;
using Iwom.Haier.Model;

namespace Iwom.Haier.Service.Impl
{
     public class HaierPageViewService : IHaierPageViewService
    {
         IHaierPageViewDao ldao = null;
        #region IHaierPageViewService 成员

         public HaierPageViewService(IHaierPageViewDao ldao)
         {
             this.ldao = ldao;
         }
        public IList<HaierPageView> FindAllByWhere(string where)
        {
            return ldao.FindAllByWhere(where);
        }
        public IList<HaierPageView> InitialByWhere(string where)
        {
            return ldao.InitialByWhere(where);
        }
        public int HaierPageView_Attitude(string where)
        {
            return ldao.HaierPageView_Attitude(where);
        }
        #endregion

       
    }
}


 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值