Java 持久性查询语言 - LIKE

The Java Persistence Query Language - LIKE

我有一个基于 Spring Web 模型-视图-控制器 (MVC) 框架的项目。 Spring Web 模型-视图-控制器 (MVC) 框架的版本是 3.2.8。

我的 DAO 中有这个方法

@Override
    public List<Application> findByQuickSearch(String searchString) {

        final StringBuilder queryString = new StringBuilder("  select app from Application app where upper (ticket_id) like :searchString or upper (id) like :searchString " );

        queryString.append(" and app.status != " + Status.DRAFT.ordinal());

        queryString.append(" order by app.submissionTime desc ");

        try {

            final Query query = getEntityManager().createQuery(queryString.toString());

            searchString = searchString.replace("!", "!!")
                       .replace("%", "!%")
                       .replace("_", "!_")
                       .replace("[", "![")
                       .trim()
                       .toUpperCase();


            System.out.println ("searchString -----> " + searchString);


            query.setParameter ("searchString", searchString);                      

            return query.getResultList();


        } catch (RuntimeException re) {
            log.error("findByCompetentBodyAndStatus failed", re);
            throw re;
        }
    }

但我意识到查询不做 LIKE 而是等于

我要找的 spring 是 "iOS/032/027""iOS/032/027" 可以,但 "iOS/""027"

不行

尝试将有效的通配符附加到 like 操作:

str_param like concat(:searchString,'%') 

Jpql doc 状态

LIKE evaluates if the two string match, '%' and '_' are valid wildcards, and ESCAPE character is optional