页面查询条件有 1 处理状态: 4.被叫号码
2 呼叫类型 5.处理坐席
3 主叫号码
在dao 层我是这么写的String hql = "from CallList as c where c.callTel = '"+callTel+"' " +
"and c.calledTelNum='"+calledTelNum+"' and c.callType='"+callType+"' and c.detailState='"+detailState+"'";但是这么写,必须所有参数和数据库中的值对应上,才能差出值来,我现在只写一个查询条件,查询就一条数据都查不出来,必须要把所有的参数写全而切是正确的,才能差出来,而且我别的条件为空也查不出来 。怎么样在写个类似模糊查询的,这样的查询怎么写啊。是不是还要加判断条件啊,我用的是SSH ,请指教大家!
2 呼叫类型 5.处理坐席
3 主叫号码
在dao 层我是这么写的String hql = "from CallList as c where c.callTel = '"+callTel+"' " +
"and c.calledTelNum='"+calledTelNum+"' and c.callType='"+callType+"' and c.detailState='"+detailState+"'";但是这么写,必须所有参数和数据库中的值对应上,才能差出值来,我现在只写一个查询条件,查询就一条数据都查不出来,必须要把所有的参数写全而切是正确的,才能差出来,而且我别的条件为空也查不出来 。怎么样在写个类似模糊查询的,这样的查询怎么写啊。是不是还要加判断条件啊,我用的是SSH ,请指教大家!
if(callTel成立表达式){
hql = hql +" and c.callTel = '"+callTel+"' ";
}
if(calledTelNum成立表达式){
hql = hql +" and c.calledTelNum= '"+calledTelNum+"' ";
}
if(callType成立表达式){
hql = hql +" and c.callType= '"+callType+"' ";
}
if(detailState成立表达式){
hql = hql +" and c.detailState= '"+detailState+"' ";
}
模糊查询就是例如这样写法
c.detailState like '%"+detailState+"%' "; 匹配全部
c.detailState like '%"+detailState+"' "; 匹配以detailState結尾
c.detailState like '"+detailState+"%' "; 匹配以detailState开始
if (callTel!=null)
{
hql+="and xxxxx"
}
else
{
if
else
}
.....
这个where的条件1=1什么意思啊
String hql = "from CallList as c where"; if (!"".equals(callTel)){
hql += "c.callTel = '"+callTel+"' ";
}
else if (!"".equals(calledTelNum)){
hql += "c.calledTelNum= '"+calledTelNum+"' ";
}
else if
......
你只要把你想要的SQL拼出来就行了。给你写个吧。
StringBuffer sqlSb=new StringBuffer();
if(!页面上传进来的值.equals(""))
{
sqlSb.append("加入对应字段的SQL字段的条件");
}
if(){}if(){}……
页面上的条件都加进来就行了。
你最后还可以把SQL语句打出来,在数据库里跑下。就很明了了。