---
title: "hibernate 多条件查询"
author: "oyprunner"
date: "2009-10-30T17:34:25Z"
tags: ["C", "C#", "C++", "Hibernate", "Java"]
slug: "hibernate"
draft: false
lastmod: "2009-10-30T17:34:25Z"
id: 507419
url: "https://oyprunner.iteye.com/blog/507419"
---

\[code="java"]public List searchClients(String clientName, String tel, String identityNo) { StringBuffer sb = new StringBuffer("from Client c where 1=1"); if(clientName != null && !"".equals(clientName) ){ sb.append("and c.name like '%" + clientName + "%'"); } if(tel != null && !"".equals(tel)){ sb.append("and c.tel = " + tel); } if(identityNo != null && !"".equals(identityNo)){ sb.append("and c.identityNo = " + identityNo); } return clientDao.searchClients(sb.toString()); }\[/code]