步骤:
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
}
}