hibernate ilike 处理大小写 包括特殊字符的查询

阅读更多
    public List 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;
    }

你可能感兴趣的:(hibernate)