如果您要坚持使用
CONTAINS,则应该是这样的:
//Get criteria builderCriteriaBuilder cb = em.getCriteriaBuilder();//Create the CriteriaQuery for Person objectCriteriaQuery<Person> query = cb.createQuery(Person.class);//From clauseRoot<Person> personRoot = query.from(Person.class);//Where clausequery.where( cb.function( "CONTAINS", Boolean.class, //assuming 'lastName' is the property on the Person Java object that is mapped to the last_name column on the Person table. personRoot.<String>get("lastName"), //Add a named parameter called containsCondition cb.parameter(String.class, "containsCondition")));TypedQuery<Person> tq = em.createQuery(query);tq.setParameter("containsCondition", "%näh%");List<Person> people = tq.getResultList();您的问题似乎缺少一些代码,因此在此代码段中我做了一些假设。



