步骤1:在com.bstek.dorado.sample.standardlesson.service.DeptService类中增加getDeptByParentId方法,最终代码如下:
package com.bstek.dorado.sample.standardlesson.service; import java.util.Collection; import java.util.HashMap; import java.util.Map; import javax.annotation.Resource; import org.springframework.stereotype.Component; import com.bstek.dorado.annotation.DataProvider; import com.bstek.dorado.sample.standardlesson.dao.SlDeptDao; import com.bstek.dorado.sample.standardlesson.entity.SlDept; @Component public class DeptService { @Resource private SlDeptDao slDeptDao; @DataProvider public Collection<SlDept> getTopDept(){ return slDeptDao.find("from SlDept where slDept.deptId is null"); } @DataProvider public Collection<SlDept> getDeptByParentId(Integer parentId){ if(null != parentId){ String hql = "from SlDept where slDept.deptId = :deptId"; Map param = new HashMap(); param.put("deptId", parentId); return slDeptDao.find(hql, param); }else{ return null; } } }
在我们展开根部门节点时,通过动态EL表达式$${this.deptId}将根节点部门的部门Id作为参数传递给后台,后台接受到参数后进行查询返回下级部门信息,这样就达到了延迟加载的目的。