oracle配置ibatis动态多条件组合模糊、分页查询_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > oracle配置ibatis动态多条件组合模糊、分页查询

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

 2013/10/9 19:02:33  Kevin12  程序员俱乐部  我要评论(0)
  • 摘要:链接地址:http://kevin12.iteye.com/blog/1953780注意的地方:&lt;就是<号,即小于号,&gt;是>号,即大于号;最近将流程项目的数据库从mysql改成oracle的数据库,原先配置的mysql的ibatis文件就不能用了,比如分页功能,模糊查询都不能用了。下面记录我修改的oracle配置ibatis的分页以及动态多条件组合,模糊查询。这里只列出来一个分页查询的ibatis文件,代码虽然有点乱,细心耐心总会有收获的:<
  • 标签:ORA 配置 Oracle
链接地址:http://kevin12.iteye.com/blog/1953780
注意的地方:&lt;就是<号,即小于号,&gt;是>号,即大于号;
最近将流程项目的数据库从mysql改成oracle的数据库,原先配置的mysql的ibatis文件就不能用了,比如分页功能,模糊查询都不能用了。下面记录我修改的oracle配置ibatis的分页以及动态多条件组合,模糊查询。这里只列出来一个分页查询的ibatis文件,代码虽然有点乱,细心耐心总会有收获的:
 
class="java">  <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 &lt;= $endRow$)row_ WHERE rownum_ &gt;$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;
	}

链接地址:http://kevin12.iteye.com/blog/1953780
发表评论
用户名: 匿名