多条件拼接SQL的查询中,用ssh,DAO中List productList = this.getHibernateTemplate().find(sql);
1个回答
展开全部
竟然你都是多条件拼接了,那么你把拼好的sql传进去不就行了
String id = map.get("id")==null?null:(String)map.get("id");
String name = map.get("name")==null?null:(String)map.get("name");
String post = map.get("post")==null?null:(String)map.get("post");
String certtype = map.get("certtype")==null?null:(String)map.get("certtype");
String status = map.get("status")==null?null:(String)map.get("status");
String dept = map.get("dept")==null?null:(String)map.get("dept");
String sqlwhere = "";
if(id!=null){
sqlwhere +=" AND ID LIKE '%"+id+"%' ";
}
if(name!=null){
sqlwhere +=" AND NAME LIKE '%"+name+"%' ";
}
if(post!=null){
sqlwhere +=" AND POST = '"+post+"' ";
}
if(certtype!=null){
sqlwhere +=" AND CERTTYPE = '"+certtype+"' ";
}
if(status!=null){
sqlwhere +=" AND STATUS = '"+status+"' ";
}
if(dept!=null){
sqlwhere +=" AND DEPT = '"+dept+"' ";
}
拼的烂点像我这样行不??
String id = map.get("id")==null?null:(String)map.get("id");
String name = map.get("name")==null?null:(String)map.get("name");
String post = map.get("post")==null?null:(String)map.get("post");
String certtype = map.get("certtype")==null?null:(String)map.get("certtype");
String status = map.get("status")==null?null:(String)map.get("status");
String dept = map.get("dept")==null?null:(String)map.get("dept");
String sqlwhere = "";
if(id!=null){
sqlwhere +=" AND ID LIKE '%"+id+"%' ";
}
if(name!=null){
sqlwhere +=" AND NAME LIKE '%"+name+"%' ";
}
if(post!=null){
sqlwhere +=" AND POST = '"+post+"' ";
}
if(certtype!=null){
sqlwhere +=" AND CERTTYPE = '"+certtype+"' ";
}
if(status!=null){
sqlwhere +=" AND STATUS = '"+status+"' ";
}
if(dept!=null){
sqlwhere +=" AND DEPT = '"+dept+"' ";
}
拼的烂点像我这样行不??
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询