如何用if判断给定String字符串?
StringqueryHql="fromPolicyInfoaspolicywherepolicy.titlelike:titleorpolicy.contentlike...
String queryHql = "from PolicyInfo as policy where policy.title like :title or policy.content like :content";
意思是如何加IF判断title 如果为空,我不执行policy.title like :title or
同理content为空不执行or policy.content like :content
都为空不执行where policy.title like :title or policy.content like :content
请问怎么实现,以前用mybaitis有if判断,现在用hibernate反而不会了。 展开
意思是如何加IF判断title 如果为空,我不执行policy.title like :title or
同理content为空不执行or policy.content like :content
都为空不执行where policy.title like :title or policy.content like :content
请问怎么实现,以前用mybaitis有if判断,现在用hibernate反而不会了。 展开
1个回答
2015-08-24
展开全部
String queryHql = "from PolicyInfo as policy
if(title != null ){
queryHql +="policy.title like :title ";
}
if(content != null){
if(title != null ){
queryHql +="or policy.content like :content"";
}else(
queryHql +="where policy.content like :content";
)
}
if(title != null ){
queryHql +="policy.title like :title ";
}
if(content != null){
if(title != null ){
queryHql +="or policy.content like :content"";
}else(
queryHql +="where policy.content like :content";
)
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询