我的一个表中有一个字段,它有一个存储urls的字段,该表的POJO如下所示:
public class ContentDefinition
{
private String contentName;
private int contentId;
private String contentType;
private String contentUrl;
}我正在尝试编写一个查询,以检查contentUrl字段是否包含以字符串address-book结尾的url。
我使用以下查询:
String hql = " from ContentDefinition WHERE contentUrl LIKE '%'address-book'%'";
Query query = getCurrentSession().createQuery(hql);
List<ContentDefinition> resultsList = query.list();但我得到了一个例外:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: address near line 1, column 130有什么解决办法吗?我的网址可以是任何东西,但总是以/address-book结尾。
发布于 2016-06-17 12:02:45
String hql = " from ContentDefinition WHERE contentUrl LIKE :addressBook ";
Query query = getCurrentSession().createQuery(hql);
query.setParameter("addressBook","address-book");
List<ContentDefinition> resultsList = query.list();发布于 2016-06-17 12:54:35
String hql =“from ContentDefinition WHERE contentUrl LIKE '%address-book%‘";
更改上面的行。其余的代码看起来不错。我测试过类似的代码。
发布于 2016-06-17 17:13:48
请阅读SQL LIKE Operator一章。
医生说:
在WHERE子句中使用LIKE运算符在列中搜索指定的模式。
where animalType like '%cats%'
这意味着,您应该将查询从以下位置更改:
String hql = " from ContentDefinition WHERE contentUrl LIKE '%'address-book'%'";至
String hql = " from ContentDefinition WHERE contentUrl LIKE '%address-book%'";https://stackoverflow.com/questions/37872806
复制相似问题