DetachedCriteria 多条件查询+时间拼接

时间拼接+多条件查询
public List<PmpTaskInfo> getAllClosedTaskInfo(String startTime,
String endTime) {

DetachedCriteria detachedCriteria = DetachedCriteria
.forClass(PmpTaskInfo.class);
if (startTime != null && startTime.length() > 0) {
startTime += " 00:00:00";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date;
try {
date = sdf.parse(startTime);
detachedCriteria.add(Expression.ge("pmpTaskCreatedtime",
new Timestamp(date.getTime())));
} catch (ParseException e) {
e.printStackTrace();
}
}
if (endTime != null && endTime.length() > 0) {
endTime += " 23:59:59";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date;
try {
date = sdf.parse(startTime);
detachedCriteria.add(Expression.le("pmpTaskCreatedtime",
new Timestamp(date.getTime())));
} catch (ParseException e) {
e.printStackTrace();
}
}
detachedCriteria.add(Expression.ne("pmpTaskEffectflag", -1));
detachedCriteria.add(Expression.eq("pmpTaskstateId", 3));
List<PmpTaskInfo> tasks = detachedCriteria.getExecutableCriteria(
getSession()).list();
return tasks;
}
建立连接查相关表的内容
public List<PmpWorkLog> findTaskLogsByTaskId(String taskId) {
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(
PmpWorkLog.class).createAlias("pmpTaskInfo", "task");
detachedCriteria.add(Expression.eq("task.pmpTaskId", Integer
.parseInt(taskId)));
List<PmpWorkLog> taskLogs = detachedCriteria.getExecutableCriteria(
getSession()).list();
return taskLogs;
}

你可能感兴趣的:(Criteria)