需求:
根据登录用户所在的部门,树形下拉框内自动显示自己以及下级部门,且用户无法看到自己的上级部门
前端代码:
<t:comboTree url="接口地址" value="" name="depid" id="depid" width="200"></t:comboTree>
具体参数请自行百度
后端代码:
TSDepart depart=(TSDepart)request.getSession().getAttribute(ResourceUtil.LOCAL_USER_DEPART);
depart = systemService.get(TSDepart.class, depart.getId());
List<TSDepart> departList = new ArrayList<>();
departList.add(depart);
ComboTreeModel comboTreeModel = new ComboTreeModel("id", "departname", "TSDeparts");
List<ComboTree> comboTrees = systemService.ComboTree(departList, comboTreeModel, null,true);
depart.getId()为部门的id,并非必须,只要能拿到需要显示的第一级部门对象即可
这里通过改写登录逻辑,在登录时将用户所在部门对象加入session即可在业务代码中获取当前登录用户的部门对象
注意:
通过此种方法获取的部门对象无法直接获取懒加载的属性
例如通过getTSDeparts()方法获取下级部门集合,在这里是无法获取的,因为hibernate已经关闭了会话,所以这里拿到id后再次查询建立了会话以用于获取下级部门集合