打开授权页面显示角色名称
role-list.jsp
location.href="${path}/system/role/toRoleModule.do?roleId="+id;
RoleController
@RequestMapping ( path= "/toRoleModule" , method = { RequestMethod. GET, RequestMethod. POST} )
public String toRoleModule ( String roleId) {
l. info ( "toRoleModule roleId=" + roleId) ;
Role role = iRoleService. findById ( roleId) ;
request. setAttribute ( "role" , role) ;
return "system/role/role-module" ;
}
页面显示效果如下图
页面发请求到后台获取数据
role-module.jsp
< link rel = " stylesheet" type = " text/css" href = " ${path}/plugins/ztree/css/zTreeStyle/zTreeStyle.css" >
< script type = " text/javascript" src = " ${path}/plugins/ztree/js/jquery-1.4.4.min.js" > </ script>
< script type = " text/javascript" src = " ${path}/plugins/ztree/js/jquery.ztree.all-3.5.min.js" > </ script>
< SCRIPT type = " text/javascript" >
var setting = {
check: {
enable: true
} ,
data: {
simpleData: {
enable: true
}
}
} ;
$ ( document) . ready ( function ( ) {
var fn = function ( data) {
$. fn. zTree. init ( $ ( "#treeDemo" ) , setting, data) ;
}
$. get ( '${path}/system/role/getZtreeData.do?roleId=${role.roleId}' , fn, 'json' )
} ) ;
</ SCRIPT>
RoleController
@RequestMapping ( path= "/getZtreeData" , method = { RequestMethod. GET, RequestMethod. POST} )
public @ResponseBody Object getZtreeData ( String roleId) {
List< Module> all = iModuleService. findAllModules ( ) ;
List< Map< String, Object> > list = new ArrayList < > ( ) ;
for ( Module m: all) {
Map< String, Object> node = new HashMap < > ( ) ;
node. put ( "id" , m. getModuleId ( ) ) ;
node. put ( "pId" , m. getParentId ( ) ) ;
node. put ( "name" , m. getName ( ) ) ;
node. put ( "open" , true ) ;
list. add ( node) ;
}
return list;
}
页面显示效果如下图
对角色的权限进行勾选显示
RoleController
@RequestMapping ( path= "/getZtreeData" , method = { RequestMethod. GET, RequestMethod. POST} )
public @ResponseBody
Object getZtreeData ( String roleId) {
List< Module> all = iModuleService. findAllModules ( ) ;
List< Module> myList = iModuleService. findModuleByRoleId ( roleId) ;
List< Map< String, Object> > list= new ArrayList < > ( ) ;
for ( Module m: all) {
Map< String, Object> node= new HashMap < > ( ) ;
node. put ( "id" , m. getModuleId ( ) ) ;
node. put ( "pId" , m. getParentId ( ) ) ;
node. put ( "name" , m. getName ( ) ) ;
node. put ( "open" , true ) ;
if ( isInMyList ( m, myList) ) {
node. put ( "checked" , true ) ;
}
list. add ( node) ;
}
return list;
}
private boolean isInMyList ( Module m, List< Module> myList) {
for ( Module my: myList) {
if ( m. getModuleId ( ) . equals ( my. getModuleId ( ) ) ) {
l. info ( "isInMyList moduleId1 " + m. getModuleId ( ) + " " + m. getName ( ) ) ;
l. info ( "isInMyList moduleId2 " + my. getModuleId ( ) + " " + my. getName ( ) ) ;
return true ;
}
}
return false ;
}
IModuleService
List< Module> findModuleByRoleId ( String roleId) ;
ModuleServiceImpl
@Override
public List< Module> findModuleByRoleId ( String roleId) {
List< Module> list= dao. findByRoleId ( roleId) ;
return list;
}
IModuleDao
List< Module> findByRoleId ( String roleId) ;
IModuleDao.xml
< select id = " findByRoleId" parameterType = " string" resultMap = " moduleMap" >
select * from pe_role_module rm inner join ss_module m
on rm.module_id=m.module_id
where rm.role_id=#{roleId}
</ select>
最终角色授权页面显示
下图是鼓励师角色的授权页面