oracle配置ibatis动态多条件组合模糊、分页查询

链接地址:[url]http://kevin12.iteye.com/blog/1953780[/url]
[color=red]注意的地方:<就是<号,即小于号,>是>号,即大于号;[/color]
最近将流程项目的数据库从mysql改成oracle的数据库,原先配置的mysql的ibatis文件就不能用了,比如分页功能,模糊查询都不能用了。下面记录我修改的oracle配置ibatis的分页以及动态多条件组合,模糊查询。这里只列出来一个分页查询的ibatis文件,代码虽然有点乱,细心耐心总会有收获的:
  <select id="IUserInf_getListForPage" parameterClass="java.util.HashMap" resultMap="codeNodeMapping">
select * from( select row_.*,rownum rownum_ from (select IUI_ID,IUI_USER_NAME,IUI_LOGIN_NAME,IUI_PASSWORD,IUI_MOBILE_PHONE,IUI_TEL,IUI_EMAIL,IUI_ID_NO,IUI_ORG_ID,IUI_IS_ADMIN,IUI_CREATE_DATETIME,IUI_LAST_UPDATE_DATETIME,IUI_LAST_UPDATE_OPERATOR_ID,IUI_VERSION,IUI_VERSION_DATE,IUI_DATA_STATUS,IUI_IS_ACTIVITY from TB_I_USER_INF a
<dynamic prepend="WHERE ">
<isNotEmpty prepend="AND" property="IUI_ID"> a.IUI_ID like '%$IUI_ID$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_USER_NAME"> a.IUI_USER_NAME like '%$IUI_USER_NAME$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_LOGIN_NAME"> a.IUI_LOGIN_NAME like '%$IUI_LOGIN_NAME$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_PASSWORD"> a.IUI_PASSWORD like '%$IUI_PASSWORD$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_MOBILE_PHONE"> a.IUI_MOBILE_PHONE like '%$IUI_MOBILE_PHONE$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_TEL"> a.IUI_TEL like '%$IUI_TEL$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_EMAIL"> a.IUI_EMAIL like '%$IUI_EMAIL$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_ID_NO"> a.IUI_ID_NO like '%$IUI_ID_NO$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_ORG_ID"> a.IUI_ORG_ID like '%$IUI_ORG_ID$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_IS_ADMIN"> a.IUI_IS_ADMIN = #IUI_IS_ADMIN#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_CREATE_DATETIME"> a.IUI_CREATE_DATETIME = #IUI_CREATE_DATETIME#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_LAST_UPDATE_DATETIME"> a.IUI_LAST_UPDATE_DATETIME = #IUI_LAST_UPDATE_DATETIME#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_LAST_UPDATE_OPERATOR_ID"> a.IUI_LAST_UPDATE_OPERATOR_ID like '%$IUI_LAST_UPDATE_OPERATOR_ID$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_VERSION"> a.IUI_VERSION = #IUI_VERSION#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_VERSION_DATE"> a.IUI_VERSION_DATE = #IUI_VERSION_DATE#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_DATA_STATUS"> a.IUI_DATA_STATUS = #IUI_DATA_STATUS#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_IS_ACTIVITY"> a.IUI_IS_ACTIVITY = #IUI_IS_ACTIVITY#</isNotEmpty>
</dynamic>
)row_ WHERE rownum <= $endRow$)row_ WHERE rownum_ >$startRow$
<dynamic prepend="ORDER BY">
<isNotEmpty property="orderSql">
$orderSql$
</isNotEmpty>
</dynamic>
</select>
<select id="IUserInf_getCount" parameterClass="java.util.HashMap" resultClass="java.lang.Long">
select count(1) as value from TB_I_USER_INF a
<dynamic prepend="WHERE ">
<isNotEmpty prepend="AND" property="IUI_ID"> a.IUI_ID like '%$IUI_ID$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_USER_NAME"> a.IUI_USER_NAME like '%$IUI_USER_NAME$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_LOGIN_NAME"> a.IUI_LOGIN_NAME like '%$IUI_LOGIN_NAME$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_PASSWORD"> a.IUI_PASSWORD like '%$IUI_PASSWORD$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_MOBILE_PHONE"> a.IUI_MOBILE_PHONE like '%$IUI_MOBILE_PHONE$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_TEL"> a.IUI_TEL like '%$IUI_TEL$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_EMAIL"> a.IUI_EMAIL like '%$IUI_EMAIL$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_ID_NO"> a.IUI_ID_NO like '%$IUI_ID_NO$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_ORG_ID"> a.IUI_ORG_ID like '%$IUI_ORG_ID$%'</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_IS_ADMIN"> a.IUI_IS_ADMIN = #IUI_IS_ADMIN#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_CREATE_DATETIME"> a.IUI_CREATE_DATETIME = #IUI_CREATE_DATETIME#)</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_LAST_UPDATE_DATETIME"> a.IUI_LAST_UPDATE_DATETIME = #IUI_LAST_UPDATE_DATETIME#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_LAST_UPDATE_OPERATOR_ID"> a.IUI_LAST_UPDATE_OPERATOR_ID = #IUI_LAST_UPDATE_OPERATOR_ID#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_VERSION"> a.IUI_VERSION = #IUI_VERSION#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_VERSION_DATE"> a.IUI_VERSION_DATE = #IUI_VERSION_DATE#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_DATA_STATUS"> a.IUI_DATA_STATUS = #IUI_DATA_STATUS#</isNotEmpty>
<isNotEmpty prepend="AND" property="IUI_IS_ACTIVITY"> a.IUI_IS_ACTIVITY = #IUI_IS_ACTIVITY#</isNotEmpty>
</dynamic>

</select>

下面是service中对ibatis文件的调用:

public <T> Pager<T> getListByPage(T obj, Integer pageSize,
Integer currentPage) {
String paths = obj.getClass().toString();
String model = paths.substring(paths.lastIndexOf(".") + 1, paths.length());
List<T> list = null;
Pager page = new Pager();
page.setPageSize(pageSize);
page.setCpage(currentPage);
Map map = MapPojoUtils.pojo2Map(obj);
Long totalSize = (Long) getSqlMapClientTemplate().queryForObject(model + "_getCount", map);
page.setTotalItem(totalSize);
// map.put("startRow", page.getPageStart()+1);
// map.put("endRow", page.getPageSize()+page.getPageStart());
map.put("startRow", page.getPageStart());
map.put("endRow", page.getPageSize());
list = getSqlMapClientTemplate().queryForList(
model + "_getListForPage", map);
page.setList(list);
return page;
}



public Pager<IUserInf> sysconfig_findUser(IUserInf user, Integer pageSize,
Integer currentPage) {
Pager<IUserInf> pager=iUserInfDao.getListByPage(user, pageSize, currentPage);
List<IUserInf> list=pager.getList();
class Sort implements Comparator<IUserInf>{
public int compare(IUserInf o1, IUserInf o2) {
return o1.getIUI_USER_NAME().compareToIgnoreCase(o1.getIUI_USER_NAME());
}
}
Collections.sort(list, new Sort());
pager.setList(list);
return pager;
}

链接地址:[url]http://kevin12.iteye.com/blog/1953780[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值