Employee 对象
private String id; //员工编号
private String name; //员工姓名
private Department department;//部门 {id,name} 页面只传depId过来
private Job job; //职务 {id ,name} 页面只传jobId过来
现在要通过四个属性(必须有一个不为空)查询相应的Employee 对象
可用DetachedCriteria criteria = DetachedCriteria.forClass(Employee.class)
criteria.add(Expression.like("id", id, MatchMode.ANYWHERE));
criteria.add(Expression.like("name", name, MatchMode.ANYWHERE));
查询部门和职务时如何写呢?***处如何写呢?有其它的方法吗?
criteria.add(Expression.eq("***", depId));
criteria.add(Expression.eq("***", jobId));
最后返回getHibernateTemplate().findByCriteria(criteria);
------解决方案--------------------
criteria.createCriteria("department").add(Expression.eq("id","depId"));
criteria.createCriteria("job").add(Expression.eq("id",jobId);
或使用hql查询
------解决方案--------------------
criteria.createCriteria("department").add(Expression.eq("id","depId"));
criteria.createCriteria("job").add(Expression.eq("id",jobId);
或使用hql查询