iBatis为业务对象添加可分页方法,扩展方法,调用Oracle
2009-11-03 14:33 闫妍 阅读(203) 评论(0) 编辑 收藏 举报以活动日志为例,打开Persistence 项目
在 interface IActionLogDao
添加接口定义
/// <summary> /// 根据可用标记获取所有的日志信息(分页) /// </summary> /// <returns></returns> List<ActionLog> GetActionLogListByActivity(ActionLog al, int start, int limit);
在ActionLogDao 中实现这个方法
/// <summary> /// 根据可用标记获取所有的日志信息(分页) /// </summary> /// <returns></returns> public List<ActionLog> GetActionLogListByActivity(ActionLog al, int start, int limit) { try { Hashtable ht = new Hashtable(); ht.Add("obj", al); ht.Add("start", start * limit + 1); ht.Add("end", start * limit + limit); return base.ExecuteQueryForList<ActionLog>("ActionLog.FindAllByObjectForPage", ht) as List<ActionLog>; } catch (Exception) { throw; } }
Services项目中使用
public DataPageInfo GetActionLogListForPageData(ActionLog al, int start, int limit) { DataPageInfo obj = new DataPageInfo(); obj.DataList = base.Change2ArrayList<ActionLog>(ActionLogDao.GetActionLogListByActivity(al, start, limit)); obj.SumNum = ActionLogDao.GetSumActionLogListByActivity(al); return obj; }
SqlMap 的XML 要加方法的SQL配置
<select id="ActionLog.FindAllByObjectForPage" parameterClass="System.Collections.IDictionary" resultMap="ActionLog_result"> SELECT * FROM (SELECT ROWNUM RN, t_t.* FROM (select * from SYS_ACTION_LOG where 1=1 <!--<isNotEmpty prepend="and" property="UserId"> USER_ID like '%$obj.UserId$%' </isNotEmpty> <isGreaterThan prepend="and" property="LoginTime" compareValue="1900-01-01"> LOGIN_TIME = #obj.LoginTime# </isGreaterThan> <isNotEmpty prepend="and" property="Action"> ACTION like '%$obj.Action$%' </isNotEmpty> <isNotEmpty prepend="and" property="UserName"> USER_NAME like '%$obj.UserName$%' </isNotEmpty> <isNotEmpty prepend="and" property="UserAttribute"> USER_ATTRIBUTE like '%$obj.UserAttribute$%' </isNotEmpty>--> order by SYS_ACTION_LOG.Id desc) t_t WHERE <![CDATA[ ROWNUM <= #end# ]]> ) <![CDATA[ WHERE RN >= #start# ]]> </select>注意,每次调试都要关闭Asp.Net 调试器
扩展一个方法,扩展一个PO,获得其中的外联表结果集合
在PO里面扩展Combo类,添加一个列表成员
/// <summary> /// 套餐代理商列表 /// </summary> private List<StoComboAgent> stoComboAgentList; /// <summary> /// 套餐代理商列表 /// </summary> private List<StoComboAgent> StoComboAgentList { get { return stoComboAgentList; } set { stoComboAgentList = value; } }
先修改该子表StoComboAgent的配置
<select id="StoComboAgent.FindByComboId" parameterClass="int" resultMap="StoComboAgent_result" extends="StoComboAgent.FindAll"> WHERE (sto_combo_agent.combo_id = #value#) </select>
<result property="StoComboAgentList" column="ID" select="StoComboAgent.FindByComboId"/>
添加新属性
先在PO的对象中添加属性
/// <summary> /// 上线时间 /// </summary> private DateTime startupTime; /// <summary> /// 上线时间 /// </summary> public DateTime StartupTime { get { return startupTime; } set { startupTime = value; } }
添加
<result property="StartupTime" column="Startup_Time"/>
再每个操作配置中都要加入这个属性
,startup_time