Commit 8c87411b authored by Sun's avatar Sun
Browse files

no commit message

parent 8ad33f02
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
*/ */
package com.jeespring.modules.sys.entity; package com.jeespring.modules.sys.entity;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
...@@ -32,7 +33,6 @@ public class Menu extends AbstractBaseEntity<Menu> { ...@@ -32,7 +33,6 @@ public class Menu extends AbstractBaseEntity<Menu> {
private Integer sort; // 排序 private Integer sort; // 排序
private String isShow; // 是否在菜单中显示(1:显示;0:不显示) private String isShow; // 是否在菜单中显示(1:显示;0:不显示)
private String permission; // 权限标识 private String permission; // 权限标识
private String userId; private String userId;
public Menu(){ public Menu(){
...@@ -45,9 +45,28 @@ public class Menu extends AbstractBaseEntity<Menu> { ...@@ -45,9 +45,28 @@ public class Menu extends AbstractBaseEntity<Menu> {
super(id); super(id);
} }
private static List<Menu> allMenuCache;
@JsonBackReference
public static List<Menu> getAllMenu() {
return allMenuCache;
}
public static void setAllMenu(List<Menu> allMenu) {
Menu.allMenuCache = allMenu;
}
@JsonBackReference @JsonBackReference
@NotNull @NotNull
public Menu getParent() { public Menu getParent() {
List<Menu> menuList = getAllMenu();
if(menuList!=null){
for (Menu item:menuList) {
if(item.parent.getId()==this.getId()) {
parent=item;
break;
}
}
}
return parent; return parent;
} }
...@@ -136,6 +155,7 @@ public class Menu extends AbstractBaseEntity<Menu> { ...@@ -136,6 +155,7 @@ public class Menu extends AbstractBaseEntity<Menu> {
@JsonIgnore @JsonIgnore
public boolean hasChildren(){ public boolean hasChildren(){
children=this.getChildren();
if(children == null || children.size() == 0){ if(children == null || children.size() == 0){
return false; return false;
} }
...@@ -205,6 +225,16 @@ public class Menu extends AbstractBaseEntity<Menu> { ...@@ -205,6 +225,16 @@ public class Menu extends AbstractBaseEntity<Menu> {
} }
public List<Menu> getChildren() { public List<Menu> getChildren() {
this.children=new ArrayList<Menu>();
List<Menu> menuList = getAllMenu();
if(menuList!=null) {
for (Menu item : menuList) {
if(item.parent==null){continue;}
if (this.getId().equals(item.parent.getId())) {
this.children.add(item);
}
}
}
return children; return children;
} }
} }
\ No newline at end of file
...@@ -54,6 +54,7 @@ public class SystemAuthorizingRealm extends AuthorizingRealm { ...@@ -54,6 +54,7 @@ public class SystemAuthorizingRealm extends AuthorizingRealm {
/** /**
* 认证回调函数, 登录时调用 * 认证回调函数, 登录时调用
* /admin/login
*/ */
@Override @Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) { protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) {
......
...@@ -180,6 +180,7 @@ public class UserUtils { ...@@ -180,6 +180,7 @@ public class UserUtils {
* @return * @return
*/ */
public static Menu getTopMenu(){ public static Menu getTopMenu(){
Menu.setAllMenu(UserUtils.getMenuList());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Menu topMenu = menuDao.findUniqueByProperty("parent_id", "'0'"); Menu topMenu = menuDao.findUniqueByProperty("parent_id", "'0'");
return topMenu; return topMenu;
......
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
<result property="isShow" column="isShow" /> <result property="isShow" column="isShow" />
<result property="permission" column="permission" /> <result property="permission" column="permission" />
<!-- 查询父模块--> <!-- 查询父模块-->
<association property="parent" column="parent_id" select="getParent" /> <!--association property="parent" column="parent_id" select="getParent" /-->
<!-- 查询子模块 --> <!-- 查询子模块 -->
<collection property="children" column="id" select="getChildren" /> <!--collection property="children" column="id" select="getChildren" /-->
</resultMap> </resultMap>
<sql id="menuColumns"> <sql id="menuColumns">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment