1 Learn
Plan
1. Role Management
N Add Role Features
N Role Paging Query
2. User Management
N Add User Features
N User Paged Query
3. Modify The authorization method in Realm (query database)
4. Use ehcache to cache permission data
N Add ehcache dependency
n Configuring the Cache Manager
5. Thesystem menu is displayed according to the login.
n Adjust page Ajax request Address
N Server-side Query menu data
2
Role Management2.1
Add a role feature2.1.1
Page Adjustments
first of all , to improve the pages/admin/function_add.jsp add permissions to the page, the drop-down box changed to Combotree
The format of his data is:
Code main Modifications Dao 's findAll method:
Function.hbm.xml modifying children for immediate loading
Added in Function.java , the successful implementation of the dropdown box modification
Then proceed to the next adjustment, open page:web-inf/pages/admin/role_add.jsp
First Step: Modify the page and use Ztree to check the effect (checkbox)
Step Two: Modify the request URL address of the Ajax method
Step three: Bind events for Save button, submit form
2.1.2
Service-Side implementation
Creating role Management Action,Service,Dao
Service Code:
Configure Struts.xml
2.2
Role Paging Query
Modify the URL address of the DataGrid in the role.jsp page
in the a paging Query method is provided in Roleaction:
3
User Management3.1
Add User
page: web-inf/pages/admin/userinfo.jsp
3.1.1
Page Adjustments
First step: Send Ajax requests, get role data, dynamically present role data in callback functions, show as checkbox
<tr> <td> Select role:</td> <td colspan= "3" id= "roletd" > <script type= "Text/javascript" > $(function(){ //after the page is loaded, send an AJAX request to get all the role data$.post (' Roleaction_listajax.action ',function(data) {//in the Ajax callback function, parse the JSON data and display it as a checkbox for(vari=0;i<data.length;i++){ varID =data[i].id; varName =Data[i].name; $("#roleTD"). Append (' <input id= ' ' +id+ ' "type=" checkbox "Name=" Roleids "value=" ' +id+ ' "><label for=" ' +id+ ' " > ' +name+ ' </label> '); } }); }); </script> </td> </tr>
the Label's for property allows you to click on the text to trigger The Click event of the checkbox.
Step two: in Roleaction provides the Listajax method, queries all roles, returns JSON data
Step three: Bind events for Save button, submit form
3.1.2
Service-Side implementation
in the The add method is provided in useraction to save a user
Service Code:
Configure Struts.xml
3.2
Paging Query
First step: Modify the URL address of the DataGrid in the userlist.jsp page
in the data table, modify field, change from phone to role
Step two: in Paging Query method available in useraction
step three: in The getrolenames method is provided in the User class , and thegetbirthdaystring method
4
Modify The authorization method in Realm (query database)
in the Functiondao extension method, Query the corresponding permissions according to the user ID
5
using ehcache to cache permission data
Ehcache is a dedicated cache plugin that can cache Java objects and improve system performance.
L Ehcache provides the jar Package:
First step: introduce ehcache dependencies in the Pom.xml file
Step Two: Provide the ehcache configuration file in the project
Step Three: Configure the Cache Manager object in the spring configuration file and inject it to the Security Manager Object
6
The system menu is displayed dynamically based on the login.
First step: Modify The request address of the Ajax method in the index.jsp page
Step two: in The findmenu method is provided in the Action
step three: in methods available in Service
Dao Code:
Note: You need to The getpid method is provided in the Function class (for displaying the parent directory)
Public String getpid () { ifnull) return "0"; return Parentfunction.getid (); }
Javaee--bos Logistics Project 12: Roles, user management, using Ehcache cache, System menu according to the login display