Easyui role Authorization (springmvc+hibernate)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.