hql: from Channel where 1=1 and channelType in :channelType and channelName like :channelName map是这样: {channelName=%有%, channelType=0,2}like 后面':channelName' 或者 :channelName 都会报错
hql: from Channel where 1=1 and channelType in :channelType and channelName like :channelName map是这样: {channelName=%有%, channelType=0,2}like 后面':channelName' 或者 :channelName 都会报错
hql: from Channel where 1=1 and channelType in :channelType and channelName like :channelName map是这样: {channelName=%有%, channelType=0,2}like 后面':channelName' 或者 :channelName 都会报错
hql: from Channel where 1=1 and channelType in :channelType and channelName like :channelName map是这样: {channelName=%有%, channelType=0,2}like 后面':channelName' 或者 :channelName 都会报错
哦, 我没注意哦, 你是Map<String, String>; channelType=0,2 这样肯定不行呀。 channelType 的实际类型必需是容器类或者数组,才能使用in,0,2这样的字符串肯定不行。 你试着调整吧。 like的没问题。如果你方法入参一定是Map<String, String>,且一定要用in, 必需重新创建一个Map<String, Object> map; map.put("channelType", params.get("channelType").split(",")): channelName字段也放进map, 把这个map传入findPage -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 我调整了一下代码,就像你说的问题不是出在like上了,而且我把map改成了<String,object>int[] channelType = {1,3}; params.put("channelType",channelType);然后查询的时候是这样:StringBuffer hql = new StringBuffer("from Channel where 1=1"); if(params.get("channelType")!=null){ hql.append(" and channelType in :channelType"); } if(params.get("channelName")!=null){ hql.append(" and channelName like :channelName"); } super.findPage(page, hql.toString(), params); return page; 错误如下: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : near line 1, column 69 [from Channel where 1=1 and channelType in :channelType and channelName like :channelName]再麻烦一下~~~
解决了,太谢谢了,我把Map改成了<String,Object> in 参数数组改成了Integer[],查询OK。神仙~~~~~谢谢你了~~~~~~劳心了~~~~~~~~
解决了,太谢谢了,我把Map改成了<String,Object> in 参数数组改成了Integer[],查询OK。神仙~~~~~谢谢你了~~~~~~劳心了~~~~~~~~问题解决了就好!
from IOSActive where 1=1 and adID='?' and appID= '?' and idfa='?'
这样我查到结果了,太谢谢了,学习了,但是这种情况,in 和like 怎么使用?比如你看我的这段代码是报错的:public Page<Channel> paging(Page<Channel> page, Map<String, Object> params) {
StringBuffer hql = new StringBuffer("from Channel where 1=1");
if(params.get("channelType")!=null){
hql.append(" and channelType in (:channelType)");
params.remove("channelType");
}
if(params.get("channelName")!=null){
hql.append(" and channelName like '%:channelName%'");
}
super.findPage(page, hql.toString(), params);
return page;
}
if(params.get("channelType")!=null){
hql.append(" and channelType in :channelType");
}query.setProperties内部会自动判断params中channelType对应的value类型,不用加();跟其它一样remove那句话去掉。like的话要这样。if(params.get("channelName")!=null){
hql.append(" and channelName like :channelName");
params.put("channelName", "%" +channelName + "%" );
}我假设你params有channelName, 用"%" +channelName + "%" 把原本的字符串覆盖掉,语句里面不加%%。你试下
params.put("channelName", "%" +params.get("channelName")+ "%" );
from Channel where 1=1 and channelType in :channelType and channelName like :channelName
map是这样:
{channelName=%有%, channelType=0,2}like 后面':channelName' 或者 :channelName 都会报错
from Channel where 1=1 and channelType in :channelType and channelName like :channelName
map是这样:
{channelName=%有%, channelType=0,2}like 后面':channelName' 或者 :channelName 都会报错
哦, 我没注意哦, 你是Map<String, String>; channelType=0,2 这样肯定不行呀。
channelType 的实际类型必需是容器类或者数组,才能使用in,0,2这样的字符串肯定不行。 你试着调整吧。
like的没问题。
from Channel where 1=1 and channelType in :channelType and channelName like :channelName
map是这样:
{channelName=%有%, channelType=0,2}like 后面':channelName' 或者 :channelName 都会报错
哦, 我没注意哦, 你是Map<String, String>; channelType=0,2 这样肯定不行呀。
channelType 的实际类型必需是容器类或者数组,才能使用in,0,2这样的字符串肯定不行。 你试着调整吧。
like的没问题。如果你方法入参一定是Map<String, String>,且一定要用in, 必需重新创建一个Map<String, Object> map;
map.put("channelType", params.get("channelType").split(",")):
channelName字段也放进map, 把这个map传入findPage
from Channel where 1=1 and channelType in :channelType and channelName like :channelName
map是这样:
{channelName=%有%, channelType=0,2}like 后面':channelName' 或者 :channelName 都会报错
哦, 我没注意哦, 你是Map<String, String>; channelType=0,2 这样肯定不行呀。
channelType 的实际类型必需是容器类或者数组,才能使用in,0,2这样的字符串肯定不行。 你试着调整吧。
like的没问题。如果你方法入参一定是Map<String, String>,且一定要用in, 必需重新创建一个Map<String, Object> map;
map.put("channelType", params.get("channelType").split(",")):
channelName字段也放进map, 把这个map传入findPage
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
我调整了一下代码,就像你说的问题不是出在like上了,而且我把map改成了<String,object>int[] channelType = {1,3};
params.put("channelType",channelType);然后查询的时候是这样:StringBuffer hql = new StringBuffer("from Channel where 1=1");
if(params.get("channelType")!=null){
hql.append(" and channelType in :channelType");
}
if(params.get("channelName")!=null){
hql.append(" and channelName like :channelName");
}
super.findPage(page, hql.toString(), params);
return page;
错误如下:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : near line 1, column 69 [from Channel where 1=1 and channelType in :channelType and channelName like :channelName]再麻烦一下~~~
解决了,太谢谢了,我把Map改成了<String,Object>
in 参数数组改成了Integer[],查询OK。神仙~~~~~谢谢你了~~~~~~劳心了~~~~~~~~
解决了,太谢谢了,我把Map改成了<String,Object>
in 参数数组改成了Integer[],查询OK。神仙~~~~~谢谢你了~~~~~~劳心了~~~~~~~~问题解决了就好!