In the system, the role table and the action table are many-to-many relationships, the general idea is to show the system's assignable menu and operation (that is, permissions), and then show that the role already has permissions, that is, send two requests, that is:
Then you want to authorize the check, press the authorization button, the data transferred to the background is very simple that is, the role of the ID (Roleid) and the authorized permissions of the ID collection (IDS):
var submitForm = function ($dialog, $grid, $pjq) {var nodes = $ (' #tree '). Tree (' getchecked ', [' checked ', ' indeterminate ']) var ids = [];for (var i = 0; i < nodes.length; i++) {Ids.push (nodes[i].id);} $.post (' Role/grantrole ', {roleid: $ (' #roleId '). Val (), Ids:ids.join (', ')}, function (Result) {if (result.success) {$ Dialog.dialog (' Destroy ');} else {$pjq. Messager.alert (' Hint ', result.msg, ' Error ');} $pjq. Messager.alert (' hint ', ' authorization succeeded! ', ' info ');}, ' json ');};
Then accept it in the background, iterating through the collection of permissions and adding each permission to that role.
Controller:
@RequestMapping ("/grantrole") public void Grantrole (httpservletrequest request,httpservletresponse response) { int Roleid = Integer.valueof (Request.getparameter ("Roleid")); String Ids=request.getparameter ("IDs"); System.out.println (IDs); Roleservice.grant (roleid,ids); JSON JSON = new JSON (); Json.setsuccess (true); Writejson (json,response);}
Roleservice.grant (Roleid,ids) in the service:
public void Grant (int roleid, String IDs) {//TODO auto-generated method Stubrole Role=roledao.getbyid (Role.class, Roleid) , if (role!=null) {role.setopeations (New hashset<operation> ()), and for (String operationId:ids.split (",")) {if (! Stringutils.isblank (OperationID)) {Operation O=operationdao.getbyid (Operation.class, OperationId), if (o!=null) { Role.getopeations (). Add (O);}}}}
Easyui role Authorization (springmvc+hibernate)