[jsp]代码库
public List<User> searchUser(final String username, final int userId,
final String lastVisitIP, final Date fromCreateDate,
final Date toCreateDate, final Date fromVisitDate,
final Date toVisitDate, final String isdesc) {
List<User> users = (List<User>) this.hibernateTemplate
.execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Criteria cr = session.createCriteria(User.class);
System.out.println("用户ID" + userId);
if (userId > 0) {
cr.add(Expression.eq("id", userId));
} else {
if (username != null && !username.equals("")) {
cr.add(Expression.like("username", "%"
+ username + "%"));
}
if (lastVisitIP != null && !lastVisitIP.equals("")) {
cr.add(Expression.like("lastVisitIP",
lastVisitIP + "%"));
}
System.out.println("时间" + fromCreateDate + " || "
+ toCreateDate + " || " + fromVisitDate
+ " || " + toVisitDate);
Date fromdate = new Date();
fromdate.setYear(02);
Date todate = new Date();
todate.setYear(998);
if (!fromCreateDate.before(fromdate)
&& !toCreateDate.after(todate)) {
cr.add(Restrictions.between("registTime",
fromCreateDate, toCreateDate));
}
if (!fromVisitDate.before(fromdate)
&& !toVisitDate.after(todate)) {
cr.add(Restrictions.between("lastVisitTime",
fromVisitDate, toVisitDate));
}
if (isdesc != null && !isdesc.equals("")) {
if (isdesc.equals("true")) {
cr.addOrder(Order.desc("id"));
} else {
cr.addOrder(Order.asc("id"));
}
}
}
return cr.list();
}
});
for (User user : users) {
System.out.println(user.getUsername() + " - " + user.getId());
}
return users;
}