hibernate ilike 处理大小写 包括特殊字符的查询
程序员文章站
2022-07-11 20:22:45
...
public List<Appconfig> getConfigListByKeyword(String keyword) { try { Session session = getSession(); Criteria criteria = session.createCriteria(Appconfig.class, "config"); if (StringUtils.isNotBlank(keyword)) { if(keyword.contains("%")){ keyword = keyword.replaceAll("%","\\\\%"); } criteria.add(Restrictions.or(Restrictions.ilike("config.configkey", "%" + keyword + "%"), Restrictions.ilike("config.keyvalue", "%" + keyword + "%"))); } return criteria.list(); } catch (Exception e) { e.printStackTrace(); } return null; }