关于Hibernate底层的查询处理(忽略大小写,模糊匹配,自动加载属性)
2014-08-28 17:05
531 查看
问题描述:Hibernate下做模糊匹配不区分大小写的时候,控制打印出来的脚本出现两个coornateName,明明我只传了一个,为什么会有两个?
①模糊匹配 like("属性",条件)
②忽略大小写 like("属性",条件).ignoreCase()
原因:HibrenateUtils.createDetachedCriteria(class,true)
会自动加载属性,也就是说只要action接收了属性对应的值,查询的时候,就会自动给该值做匹配(=)
原始脚本:
然后把HibrenateUtils.createDetachedCriteria(class,true)
换成DetachedCriteria.forClass(TCoordinate.class);
完整的java代码:
模糊匹配,忽略大小写的关键代码:
dc.add(Restrictions.like("coordinateName", conditions.getCoordinateName(),MatchMode.ANYWHERE).ignoreCase());
①模糊匹配 like("属性",条件)
②忽略大小写 like("属性",条件).ignoreCase()
原因:HibrenateUtils.createDetachedCriteria(class,true)
会自动加载属性,也就是说只要action接收了属性对应的值,查询的时候,就会自动给该值做匹配(=)
原始脚本:
select this_.id as id24_0_, this_.axisId as axisId24_0_, this_.isLock as isLock24_0_, this_.addDate as addDate24_0_, this_.coordinateName as coordina5_24_0_, this_.PROCESSID as PROCESSID24_0_, this_.parentId as parentId24_0_, this_.coordinateValue as coordina8_24_0_, this_.isValid as isValid24_0_, this_.adduser as adduser24_0_ from t_coordinate this_ where this_.coornaditeName = ? <pre name="code" class="sql"><span style="white-space:pre"> </span>and lower(this_.coordinateName) like ?and this_.axisId=? order by this_.addDate desc
然后把HibrenateUtils.createDetachedCriteria(class,true)
换成DetachedCriteria.forClass(TCoordinate.class);
select this_.id as id24_0_, this_.axisId as axisId24_0_, this_.isLock as isLock24_0_, this_.addDate as addDate24_0_, this_.coordinateName as coordina5_24_0_, this_.PROCESSID as PROCESSID24_0_, this_.parentId as parentId24_0_, this_.coordinateValue as coordina8_24_0_, this_.isValid as isValid24_0_, this_.adduser as adduser24_0_ from t_coordinate this_ where this_.axisId=? and lower(this_.coordinateName) like ? order by this_.addDate desc
完整的java代码:
public Page getCoordByPage(Page queryHandler, TCoordinate conditions) { DetachedCriteria dc = DetachedCriteria.forClass(TCoordinate.class); if (conditions.getTAxis() != null) { dc.add(Restrictions.eq("TAxis", conditions.getTAxis())); } if(conditions.getCoordinateName()!=null){ dc.add(Restrictions.like("coordinateName", conditions.getCoordinateName(),MatchMode.ANYWHERE).ignoreCase()); } if(conditions.getParentCoordinate().getId()!=null){ dc.add(Restrictions.eq("parentCoordinate.id", conditions.getParentCoordinate().getId())); } dc.addOrder(Order.desc("addDate")); Page page = this.coordinateDao.getPageByCriteria(queryHandler, dc); return page; }
模糊匹配,忽略大小写的关键代码:
dc.add(Restrictions.like("coordinateName", conditions.getCoordinateName(),MatchMode.ANYWHERE).ignoreCase());
相关文章推荐
- 如何在SQL模糊查询中忽略对大小写字符的处理
- 关于前台模糊查询处理实例
- 动态SQL— —模糊查询语句(存储过程)中关于百分号%的处理
- 关于Hibernate实体类属性名的大小写的问题,出现了找不到该属性的错误
- 关于js中处理时间戳和图片预加载的问题自动提交
- Oracle SQL忽略大小写模糊查询
- 模糊查询——忽略大小写小技巧
- oracle 模糊查询 忽略大小写
- 原生ajax 实现输入框模糊查询,自动匹配数据库数据
- Oracle数据库,忽略大小写Like模糊查询(SQL Server,MySql原理相同)
- oracle 模糊查询忽略大小写
- winform实现combox控件自动匹配查找,模糊查询功能
- hibernate 关于date类型的模糊查询解决方法
- SQL 忽略大小写模糊查询
- Oracle-模糊查询忽略大小写
- 动态SQL模糊查询语句(存储过程)中关于百分号%的处理
- 首字母自动匹配与模糊查询
- 关于SQLServer存储过程动态拼接,模糊查询的处理
- C# Xamarin.Parse 模糊查询 忽略大小写
- AJAX异步请求,底层使用hibernate查询后的数据json封装之前的处理