数据查询中 IN关键字的使用方法总结
来源:互联网 发布:价签软件 编辑:程序博客网 时间:2024/06/15 03:52
第一种(在hql语句中的where条件中拼接好in的内容):
List<TUmUserrole> roleList = hibernateDao.queryObjectsByWhere(TUmUserrole.class, wherePart, parmaters.toArray(),sortField, null, null);String rolesStr = "";// 所有rolepid组合字符串if (null != roleList && roleList.size() > 0) {// userrole不为空时,取到所有的rolepid ,根据所有rolepid去rolelimits表中找所有的limitsfor (TUmUserrole userRole : roleList) {if (rolesStr != "")rolesStr += ",";rolesStr += "'" + userRole.getRolepid() + "'";}}user.setRolepid(rolesStr);String limitsStr = "";if (StringUtil.notEmpty(rolesStr)) {parmaters.clear();wherePart = " ROLEPID IN ( " + rolesStr + " ) ";wherePart += " AND STATUS = ? ";parmaters.add(ISuperVO.STATUS_ACTIVE);sortField = " UPDATEDATETIME DESC";List<TUmRolelimits> limitList = hibernateDao.queryObjectsByWhere(TUmRolelimits.class, wherePart,parmaters.toArray(), sortField, null, null);
第二种(在如下回调中使用list类型参数):
List orgList = null;StringBuffer wherePart = new StringBuffer();List<Object> parmaters = new ArrayList<Object>();//指定区域查询if (StringUtil.notEmpty(entity.getAreaCode())) {wherePart.append("arCd = ?");parmaters.add(entity.getAreaCode());}orgList = this.hibernateDao.queryObjectsByWhere(Healthorgreg.class, wherePart.toString(), parmaters.toArray(), null, null, null);List tempList = new ArrayList();for(int i=0;i<orgList.size();i++){Healthorgreg healthOrgReg = (Healthorgreg) orgList.get(i);tempList.add(healthOrgReg.getOrganizationCode());}//List resultList = null;StringBuffer wherePart1 = new StringBuffer();List<Object> parmaters1 = new ArrayList<Object>();// 指定机构代码查询wherePart1.append("belongOrgCode in(:typeids)");parmaters1.add(tempList);resultList = this.hibernateDao.queryObjectsByWhere(Hospitalassets.class, wherePart1.toString(),parmaters1.toArray(), null, null, null);
@SuppressWarnings("unchecked")public List queryObjectsByWhere(Class cl, String wherePart,Object[] parmaters, String sortField, Integer startRow,Integer rowCount) throws DaoException {try {if (cl == null) {throw new DaoException(DaoExceptionType.TYPE_CODE_PARAM_NULL,"vo is not null");}String hql = "from " + cl.getName() + " where 1=1 ";if (wherePart != null && wherePart.trim().length() > 0) {hql = hql + " and " + wherePart;}if (sortField != null && sortField.trim().length() > 0) {hql = hql + " order by " + sortField;}return queryObjectsByHQL(hql, parmaters, startRow, rowCount);} catch (Exception e) {throw new DaoException(DaoExceptionType.TYPE_CODE_DAO, e);}}
@SuppressWarnings("unchecked")public List queryObjectsByHQL(final String HQLStr,final Object[] parmaters, final Integer startRow,final Integer rowCount) throws DaoException {try {List list = getHibernateTemplate().executeFind(new HibernateCallback() {public Object doInHibernate(Session session)throws HibernateException, SQLException {Query query = session.createQuery(HQLStr);if (startRow != null && startRow.intValue() >= 0&& rowCount != null&& rowCount.intValue() >= 0) {query.setFirstResult(startRow);query.setMaxResults(rowCount);}if (parmaters != null && parmaters.length > 0) {for (int i = 0; i < parmaters.length; i++) {if((parmaters[i]) instanceof List){List tempList = (List) parmaters[i];query.setParameterList("typeids", tempList);}else{query.setParameter(i, parmaters[i]);}}}List list = query.list();return list;}});return list;} catch (Exception e) {throw new DaoException(DaoExceptionType.TYPE_CODE_DAO, e);}}
- 数据查询中 IN关键字的使用方法总结
- js 关键字 in 的使用方法
- js 关键字 in 的使用方法
- js 关键字 in 的使用方法
- oralce数据库中使用in关键字查询时配合order by instr与in关键字相同顺序的查询
- MySQL带IN关键字的查询
- MySQL带IN关键字的子查询
- 数据查询时几个关键字(IN、OR、EXIST)的效率分析
- ibatis中"in"的使用方法
- MyBatis 中 in 的使用方法
- extern关键字使用方法总结
- Mysql 中 查询结果顺序按 IN 关键字中ID 的排列
- SQL中TOP关键字的使用方法
- Java中final关键字的使用方法
- Java多线程中synchronized关键字的使用方法
- c语言中常用关键字的使用方法
- 在sql语句中in关键字提示查询性能
- 在sql语句中in关键字提示查询性能
- 动态查找之二叉排序树(BST)
- 使用VS2010时遇到的一些小问题的解决方案(从各处搜罗总结的,不定期更新,向原作者致敬)
- JAVA 继承基本类、抽象类、接口
- ubuntu 10.04安装sun-java5-jdk
- android在自定义View的xml中设置自定义的成员属性
- 数据查询中 IN关键字的使用方法总结
- VC系统消息总结
- Redis 的安装配置介绍
- Struts2教程1:第一个Struts2程序
- Mysql Integer 时间转换
- 九度OJ 1003 A+B
- 破解启动密码SYSKEY
- Coder
- wince获取屏幕分辨率