查询菜单树的方法

6 篇文章 0 订阅
2 篇文章 0 订阅
菜单树

以查询部门为例,查询的部门的所在菜单,有它的父级菜单和子级菜单,要求通过部门id直接查询该部门所在的部门菜单树
以Springboot为例子,该篇为学习笔记

/**根据部门id查询部门树**/
/**自定义的Service可自定义端口,这里我定义的部门树接口是DeptTree**/
@Service("DeptTree")
public List<Ztree> selectDept(Dept dept,SqlSession sqlSession) throws Exception{
	/**查询前先给菜单树为空**/
	List<Ztree> ztrees = null;
	/**这里设置两个断言,dept和CommunityId是必传字段不能为空**/
	Assert.notNull(dept,"部门不可为空");
	Assert.notNull(dept.getCommunityId(),"小区id不可为空");
	try{
		/**打印前端传递来的参数**/
		logger.info("开始查询菜单树,请求参数:{}",dept);
		/**定义部门树集合,将DeptMapper下的属性放在list中**/
		List<Dept> deptList = sqlSession.getMapper(DeptMapper.class).list(dept);
		/**将放了属性的部门集合交给树**/
		ztrees = initZtree(deptList);
	}catch(Exception e){
		logger.error("出现异常",e);
		throw new Exception(CommConstant.ERROR_CODE,"查询菜单树异常");
	}
	return ztrees;
}
/**对象转部门树**/
private List<Ztree> initZtree(List<Dept> deptList){
	List<Ztree> ztrees = new ArrayList<>();
	for(Dept dept : deptList){
		if(CommConstant.TATA_ACTIV_FALG.equals(dept.getStatusCd())){
			Ztree ztrees  = new Ztree();
			/**在这里将获取的dept中的属性get出来放进新的部门树ztrees中**/
			ztree.setId(dept.getDeptId());
			ztree.setpId(dept.getParentId());  
			ztree.setName(dept.getName());  
			ztree.setTitle(dept.getLevel());  
			/**添加菜单树**/
			ztrees.add(ztree)   
		}
	}
	return ztrees;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值