实体类:
public class User implements Serializable
{
private static final long serialVersionUID = 120215L;
private long id;
private String name;
private int age;
private String role;
get...略
set...略
}
查询方法
public static List selectUser(User u,int first,int max)
{
List list = null;
try
{
User user = new User();
BeanUtils.copyProperties(user,u);
Session session = Hibernate.getCurrentSession();
Criteria criteria = session.createCriteria(User.class);
int age = user.getAge();
if(age == 0)
{
user.setAge(0);
criteria.add(Restrictions.sqlRestriction("age<20"));
}
criteria = criteria.add(Example.create(user));
if(first == 0 && max == 0)
list = criteria.list();
else
{
criteria.setFirstResult(first);
criteria.setMaxResults(max);
list = criteria.list();
}
}catch(Exception e)
{
log.error(".....");
log.error(e);
e.printStackTrace();
}
finally
{
Hibernate.closeSession();
}
return list;
}
生成的查询语句总跟着个...and (this.age=?) ,请问怎样去掉默认的age=0