오픈 소스 프로젝트에 권한 구성 기능을 추가 할 계획이며 Ztree를 추가하여 트리 구조를 구현할 계획입니다.
Team 's Github 오픈 소스 프로젝트 링크 : https://github.com/u014427391/jeepatform Welcomes Star (Collection)
Ztree는 jQuery가 구현 한 다기능 "트리 플러그인"입니다. 탁월한 성능, 유연한 구성 및 여러 기능의 조합이 Ztree의 가장 큰 장점입니다.
Ztree 다운로드 링크 : http://www.treejs.cn/v3/main.php#_ztreeinfo
역할 정보 엔티티 클래스 :
패키지 org.muses.jeepatform.core.entity.admin; import javax.persistence.*; import java.io.serializable; import java.util.hashset; import java.util.set;/*** @descrection real room eternity class* @author nicky* @date 3 월 16, 2017*/@table (name = "sys_role")@EntityPublic 클래스 역할은 직렬화 가능한 {/** roble id **/private int roleceid를 구현합니다. / ** 역할 설명 **/ 개인 문자열 ROLEDESC; / ** 역할 이름 **/ 개인 문자열 롤레나 이름; / ** 역할 플래그 **/ 개인 문자열 역할; 비공개 세트 <bermission> 권한 = 새로운 해시 세트 <bermission> (); @id @generatedValue (전략 = GenerationType.Identity) public int getroleid () {return roleceid; } public void setroleid (int roleceid) {this.roleid = relearid; } @Column (길이 = 100) public String getRoleDesc () {return roledesc; } public void setroledesc (String roledesc) {this.roledesc = roledesc; } @Column (길이 = 100) public String getRolEname () {return rolename; } public void setRolEname (String rolename) {this.rolename = rolename; } @Column (길이 = 100) public String getRole () {return 역할; } public void setrole (문자열 역할) {this.role = 역할; } // 캐스케이드 정책을 캐스케이드 관계 @onetomany로 수정합니다 (targetentity = hermission.class, cascade = cascadetype.merge, fetch = fetchtype.eger) @jointable (name = "sys_role_permission", joincolumns = @joincolumn (name = ""= "" ""ropentcolumnname = " inversejoincolumns =@joincolumn (name = "permissionId", referenceColumnName = "id", 고유 = true)) public set <bermission> getpermissions () {return extrions; } public void setPermissions (set <bermission> 권한) {this.permissions = 권한; } @override public boolean equals (Object obj) {if (obj instanceof roin) {역할 역할 = (역할) obj; reture this.roleid == (role.getRoleid ()) && this.rolename.equals (role.getRolename ()) && this.roledesc.equals (role.getRoledesc ()) && this.role.equals (role.getRole ()); } return super.equals (obj); }}권한 정보 엔티티 클래스 :
패키지 org.muses.jeepatform.core.entity.admin; import java.io.serializable; import java.util.hashset; import java.util.set; import javax.persistence.cascadetype; import javax.persistence.column; import javax.peristence.entity; javax; javax; javax.persistence.generatevalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.jointable; import javavs.persistence.manytomany; javax.persist javax.persistence.table;/*** 권한 작업을위한 @description vo class* @author nicky* @date 2017 년 3 월 6 일*/ @table (name = "sys_permission") @entityPublic 클래스 권한 구현 시리얼이즈 가능 {private int id; 개인 문자열 pdesc; 개인 문자열 이름; 개인 정적 최종 최종 긴 SerialversionUID = 1L; 개인 메뉴 메뉴; 비공개 세트 <peration> 작업 = New Hashset <작동> (); 공개 허가 () {super (); } @generatedValue (전략 = GenerationType.Inderity) @ID public int getId () {return this.Id; } public void setid (int id) {this.id = id; } @Column (길이 = 100) public String getPdesc () {return this.pdesc; } public void setpdesc (String pdesc) {this.pdesc = pdesc; } @Column (길이 = 100) public String getName () {return this.name; } public void setName (문자열 이름) {this.name = 이름; } @onetoone (targetentity = menu.class, cascade = cascadetype.refresh, fetch = fetchtype.eager) @joincolumn (name = "menuid", referencecolumnname = "menuid") public menu getMenu () {return menu; } public void setMenu (메뉴 메뉴) {this.menu = 메뉴; } @manytomany (Targetentity = Operation.Class, Cascade = Cascadetype.Merge, fetch = fetchType.eger) @jointable (이름 = "sys_permission_operation", joincolumns =@joincolumn (name = "permissionId", referenceColumnName = "id"), inversejoincolumns =@joincolumn (name = "OperationId", 참조 콜럼나 이름 = "id")) public set> getOperations () {return operations (getOperations;); } public void setOperations (set <peration> 조작) {this.operations = 조작; }}JPA를 사용하여 구현하는 메뉴 정보 엔티티 클래스 구현
package org.muses.jeepatform.core.entity.admin; import javax.persistence.*; import java.io.serializable; import java.util.list;/*** @description 메뉴 정보 엔티티* @author nicky* @date 2017 년 3 월 17 일*/ @table (name = "sys _menu") @entitypublic instrements. { / ** 메뉴 ID ** / private int menuid; / ** 우수한 ID **/ private int parentid; / ** 메뉴 이름 **/ 개인 문자열 메뉴 이름; / ** 메뉴 아이콘 **/ 개인 문자열 메뉴; / ** 메뉴 URL **/ 개인 문자열 메뉴; / ** 메뉴 유형 **/ 개인 문자열 menutype; / ** 메뉴 정렬 **/ 개인 문자열 menuorder; / ** 메뉴 상태 **/ 개인 문자열 menustatus; 개인 목록 <메뉴> 하위 메뉴; 개인 문자열 대상; 개인 부울 Hassubmenu = 거짓; 공개 메뉴 () {super (); } @id @generatedValue (전략 = GenerationType.identity) public int getMenuid () {return this.menuid; } public void setMenuid (int menuid) {this.menuid = menuid; } @Column (길이 = 100) public int getParentId () {return parentid; } public void setparentId (int parentid) {this.parentid = parentid; } @Column (길이 = 100) public String getMenUname () {return this.menUname; } public void setMenUname (String Menuname) {this.menuname = menuname; } @Column (길이 = 30) public String getMenuicon () {return this.menuicon; } public void setMenuicon (String Menuicon) {this.menuicon = menuicon; } @Column (길이 = 100) public String getMenuurl () {return this.menuurl; } public void setMenuurl (String Menuurl) {this.menuurl = menuurl; } @column (length = 100) public String getMenUtype () {return this.menutype; } public void setMenUtype (String Menutype) {this.menutype = menutype; } @Column (길이 = 10) public String getMenuorder () {return Menuorder; } public void setMenuorder (String Menuorder) {this.menuorder = menuorder; } @Column (길이 = 10) public String getMenustatus () {return menustatus; } public void setMenustatus (String menustatus) {this.menustatus = menustatus; } @transient public list <메뉴> getSubmenu () {return submenu; } public void setsubmenu (list <menu> submenu) {this.submenu = submenu; } public void settarget (문자열 target) {this.target = target; } @transient public String getTarget () {return target; } public void sethassubmenu (부울 하부 메 누) {this.hassubmenu = hassubmenu; } @transient public boolean gethassubmenu () {return hassubmenu; }}jparepository 인터페이스를 구현하십시오
패키지 org.muses.jeepatform.core.dao.repository.admin; import org.muses.jeepatform.core.entity.admin.role; import org.springframework.data.jpa.repository.jparepository;/*** 2017/12/2에 생성 된 ****. */public interface rolerepository 확장 jparepository <역할, integer> {}jparepository 인터페이스를 구현하십시오
Package org.muses.jeepatform.core.dao.repository.admin; import org.muses.jeepatform.core.entity.admin.menu; import org.springframework.data.jpa.repository.jparepository;/*** 2017/6/17에 만들어졌습니다. */public interface menutreeRepository 확장 jparepository <menu, integer> {}역할 서비스 수업 :
패키지 org.muses.jeepatform.service; import com.google.common.collect.lists; import org.muses.jeepatform.core.dao.repository.admin.rolepagerepository; import org.muses.jeepatform.core.entity.admin.role; import org.springframework.beans.bean.annotation.autowired; import org.springframework.data.domain.pagerequest; import org.sprameframework.data.domain.sort; import org.spramepramework.sterople.service; import java.util.list;/*** of 2017/30. */ @servicepublic class rolepageservice {@autowired rolepagerepository rolerepository; / ** * 빌드 pagerequest 객체 * @param num * @param size * @param asc * @param string * @return */ private pageRequest buildPageRequest (int num, int size, sort.direction ASC, String String) {return new pageRequest (num-1, size, null, string); } / *** 모든 메뉴 정보를 가져 와서 페이지에 표시* @param pageno* 현재 페이지* @param pagesize* 페이지 당 페이지 수* / public page <brole> findall (int pageno, int pagesize, sort.diperection dir, string str) {pagerequest pagerequest = buildpagerquest (pageno, dir, str); page <brole> 역할 = rolerepository.findall (Pagerequest); 반환 역할; } public list <brole> findAllRole () {iterable <brole> 역할 = rolerepository.findall (); 목록 <brole> mylist = lists.newarraylist (역할); MyList를 반환하십시오. } / ** * 역할 Id * @param roleceid * @return * / Public Real FindByRoleid (String RoleID) {return rolerepository.findone (integer.parseint (roleid)); } / *** 역할 정보 저장* @param 역할* / public void dosave (역할 역할) {rolerepository.save (역할); }}메뉴 서비스 수업 :
패키지 org.muses.jeepplatform.service; import org.muses.jeepplatform.annotation.rediscache; import org.muses.jeepplatform.common.rediscachenamespace; import org.muses.jeepplatform.core.dao.repository org.muses.jeepplatform.core.entity.admin.menu; import org.springframework.bean.beans.annotation.autowired; import org.springframework.stereotyp.service; import org.spramework.transaction.annotation.transactional;/** on on on on on on on on on on on on on on on on on on on on hone java. 2017/6/17. */ @servicepublic class menutreeservice {@autowired menutreerepository menutreerepository; /*** 모든 메뉴* @return*/@transactional // @readiscache public list <메뉴> findall () {return menutreerepository.findall (); }}컨트롤러 클래스에서 역할 ID를 사용하여 역할이 볼 수있는 메뉴를 얻으십시오.
/** * 역할 승인 페이지로 점프 * @param rolealId * @param model * @return */@requestmapping (value = "/goauthorise") public string goauth (@requestparam String roleorid, model model) {list <menu> menulist = menutreeservice.findall (); 역할 역할 = Roleservice.FindByRoleid (roleid); <bermission> haspermissions = null을 설정하십시오. if (role! = null) {hasperMissions = role.getPerMissions (); } for (menu m : menulist) {for (허가 p : haspermissions) {if (p.getMenu (). getMenuid () == M.GetMenUid ()) {M.SetHassubMenu (true); }}} model.addattribute ( "rolId", rolId); jsonarray jsonarray = jsonarray.fromobject (menulist); 문자열 json = jsonarray.tostring (); json = json.replaceall ( "menuid", "id"). replaceall ( "parentid", "pid"). replaceall ( "menuname", "name"). replaceall ( "hassubmenu", "Checked"); model.addattribute ( "메뉴", JSON); "admin/role/role_auth"를 반환합니다. }프론트 엔드에서 트리 메뉴 디스플레이는 Ztree를 통해 실현 된 다음 다음을 확인하여 역할 승인을 구현합니다.
<%@ page contenttype = "text/html; charset = utf-8"pageencoding = "utf-8"%> <%@ taglib prefix = "c"uri = "http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%> <% string path = request.getContextPath (); String BasePath = request.getScheme ()+": //"+request.getServerName ()+":"+request.getServerport ()+path+"/";%> <! doctype html> <html lang = "zh-cn"> <head> <vase> charset = "utf-8"/> <meta http-equiv = "x-ua-catsible"content = "ie = edge"> <meta name = "viewport"content = "width = device-width, feative-width, initial-scale = 1"> <title> 제목 </title> <!-jquery 라이브러리 소개-> <텍스트/javascript " src = "$ {basepath} static/js/jquery-1.8.3.js"> </script> <!-jQuery 라이브러리 소개-> <script type = "text/javaScript"src = "<%= BasePath%> 플러그인/zdialog/zdialog.js"> src = "<%= basepath%> 플러그인/zdialog/zdialog/zdrag.js"> </script> <script type = "text/javaScript"src = "<%= basepath%> 플러그인/zdialog/zdrag.js"> </script> <script> <script> <script> javascript " src = "<%= basepath%> 플러그인/zdialog/zprogress.js"> </script> <link rel = "stylesheet"href = "<%= basepath%> 플러그인/ztree/3.5/ztreestyle.css"rel = "external nofollow"type/css "> <script ="text/javascript " src = "<%= basepath%> 플러그인/ztree/3.5/jquery-1.4.4.min.js"> </script> <script type = "text/javaScript"src = "<%= basepath%> 플러그인/ztree/3.5/jquery.ztree.core.js"> src = "<%= basepath%> 플러그인/ztree/3.5/jquery.ztree.excheck.js"> </script> <script type = "text/javaScript"> <!- var settent = {check : {true}, data : {simpledata : {onable}}; /*. var znodes = val (json); var 코드; 함수 setcheck () {var ztree = $ .fn.ztree.getztreeobj ( "treedemo"), py = $ ( "#py"). attr ( "Checked")? "p": "", sy = $ ( "#sy"). attr ( "Checked")? "s": "", pn = $ ( "#pn"). att ( "Checked")? "p": "", sn = $ ( "#sn"). art ( "Checked")? "s": "", type = { "y": py + sy, "n": pn + sn}; ztree.setting.check.chkboxtype = 유형; showcode ( 'setting.check.chkboxtype = { "y": "' + type.y + '", "n": "' + type.n + '"};'); } 함수 showcode (str) {if (! code) code = $ ( "#code"); code.empty (); Code.Append ( "<li>"+str+"</li>"); . $ ( "#sn"). bind ( "Change", setCheck); //-> 함수 chanfclose () {parentDialog.close (); } function dosave () {var ztree = $ .fn.ztree.getztreeobj ( "treedemo"); var 노드 = ztree.getCheckedNodes (); var tmpnode; var ids = ""; for (var i = 0; i <nodes.length; i ++) {tmpnode = 노드 [i]; if (i! = nodes.length-1) {ids += tmpnode.id +","; } else {ids += tmpnode.id; }} var robolId = $ {roleiid}; var params = roleid +";" +ids; 경고 (IDS); $ .ajax ({type : "post", url : 'role/suthorise.do', data : {params : params : tm : new date (). gettime ()}, dataType : 'json', cache : cache : cache : function (data) {if ( "success"== data.result) {Alert! dodialogclose () {alert ( "권한 실패!}}); } </script> </head> <body> <div> <div> <ul id = "treedemo"> </ul> </div> </div> <입력 유형 = "button"onclick = "doSave ()"value = "save"/> <input onclick = "dialogclose ();"; type = "button"value = "close"/> </body> </html>팀의 GitHub 오픈 소스 프로젝트 링크 : https://github.com/u014427391/jeepatform
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.