044 根据权限动态展示菜单 - bos
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了044 根据权限动态展示菜单 - bos相关的知识,希望对你有一定的参考价值。
1.修改index.jsp页面中ajax请求的url为functionAction_findMenu.action,请求菜单数据
2.实现FunctionAction.findMenu方法
/**
* 根据当前登录的用户查询对应的菜单数据,返回json
* @return
*/
public String findMenu(){
List<Function> functionList = functionService.findMenu();
list2JsonAndWriteResponse(functionList, "parentFunction" , "roles", "children");
return NONE;
}
3.实现FunctionService.findMenu
@Override
public List<Function> findMenu() {
List<Function> functionList = null;
User user = BOSUtils.getLoginUser();
if(user.getUsername().equals("admin")){
//如果是内置用户,则查询所有菜单
functionList = functionDao.findAllMenu();
}else{
//其他用户,根据用户ID查询菜单
functionList = functionDao.findMenuByUserId(user.getId());
}
return functionList;
}
4.实现FunctionDao.findAllMenu();
/**
* 查询所有菜单
*/
@Override
public List<Function> findAllMenu() {
String hql = "from Function f where f.generatemenu = ‘1‘ ORDER BY f.zindex";
@SuppressWarnings("unchecked")
List<Function> list = (List<Function>) getHibernateTemplate().find(hql);
return list;
}
5.实现FunctionDao.findMenuByUserId
@Override
public List<Function> findMenuByUserId(String id) {
//涉及5张表的关联查询,使用hql由于省略的中间表,剩下3个类的关联查询
String hql = "SELECT DISTINCT f FROM Function f LEFT OUTER JOIN f.roles r LEFT OUTER JOIN r.users u "
+ " WHERE u.id=? AND f.generatemenu = ‘1‘ "
+ "ORDER BY f.zindex";
@SuppressWarnings("unchecked")
List<Function> find = (List<Function>) getHibernateTemplate().find(hql, id);
return find;
}
以上是关于044 根据权限动态展示菜单 - bos的主要内容,如果未能解决你的问题,请参考以下文章