NutzCN Logo
问答 多对多关联 多对多查询
发布于 6天前 作者 Hamming 71 次浏览 复制 上一个帖子 下一个帖子
标签:

用户 有多个角色 ;一个角色有多个菜单

package io.nutz.nutzsite.module.sys.models;

import io.nutz.nutzsite.common.base.Model;
import org.nutz.dao.entity.annotation.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 用户信息
 */
@Table("sys_user")
public class User extends Model implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column
    @Comment("ID")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    @Prev(els = {@EL("uuid()")})
    private String id;

    /**
     * 角色集合
     */
    @ManyMany(from = "user_id", relation = "sys_user_role", to = "role_id")
    private List<Role> roles;

package io.nutz.nutzsite.module.sys.models;

import io.nutz.nutzsite.common.base.Model;
import org.nutz.dao.entity.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 角色表
 */
@Table("sys_role")
public class Role  extends Model implements Serializable {
    private static final long serialVersionUID = 1L;

    @ManyMany(from = "role_id", relation = "sys_role_menu", to = "menu_id")
    protected List<Menu> menus;

}

package io.nutz.nutzsite.module.sys.models;

import io.nutz.nutzsite.common.base.Model;
import org.nutz.dao.entity.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Hamming_Yu on 2018/12/29.
 */
@Table("sys_menu")
public class Menu extends Model implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column
    @Name
    @Comment("ID")
    @ColDefine(type = ColType.VARCHAR, width = 64)
    @Prev(els = {@EL("uuid()")})
    private String id;

    @Column("menu_name")
    @Comment("菜单名称")
    @ColDefine(type = ColType.VARCHAR, width = 100)
    private String menuName;

    @Column("parent_id")
    @Comment("父菜单ID")
    @ColDefine(type = ColType.VARCHAR, width = 64)
    private String parentId;

    /**
     * 父菜单名称
     */
    private String parentName;

    @Column("order_num")
    @Comment("显示顺序")
    private String orderNum;

    @Column("url")
    @Comment("菜单URL")
    private String url;

    @Column("menu_type")
    @Comment("类型:0目录,1菜单,2按钮")
    private String menuType;

    @Column("visible")
    @Comment("菜单状态:0显示,1隐藏")
    private boolean visible;

    @Column("perms")
    @Comment("权限字符串")
    private String perms;

    @Column
    @Comment("菜单图标")
    private String icon;

    @Column
    @Comment("备注")
    private String remark;

    /** 子菜单 */
    private List<Menu> children = new ArrayList<Menu>();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getParentName() {
        return parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }

    public String getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(String orderNum) {
        this.orderNum = orderNum;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMenuType() {
        return menuType;
    }

    public void setMenuType(String menuType) {
        this.menuType = menuType;
    }

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public String getPerms() {
        return perms;
    }

    public void setPerms(String perms) {
        this.perms = perms;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public List<Menu> getChildren() {
        return children;
    }

    public void setChildren(List<Menu> children) {
        this.children = children;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
}

能直接fetchLinks 角色 roles menus吗

this.fetchLinks(user, "roles","menus");
2 回复

第二个参数是正则表达式

this.fetchLinks(user, "roles|menus");

用户 有多个角色 角色 下面 有 多个菜单
fetchLinks 不能把 roles 关联的menus 查出来

添加回复
请先登陆
回到顶部