SpringBoot+JPA+thymeleaf 菜单分级展示

Control

  List<PRPSPOWER> prpspowers=  powerService.getPowerByUserCode(usercode);
            for (int i = 0; i < prpspowers.size(); i++) {
                PRPSPOWER menu = prpspowers.get(i);
                List<PRPSPOWER> childMenuList = new ArrayList<>();
                //2、菜单分级展示
                if ("1".equals(menu.getMlevel())) {
                    for (int j = 0; j < prpspowers.size(); j++) {
                        if (Objects.equals(menu.getPowerid(), prpspowers.get(j).getUppermenuid())){
                            childMenuList.add(prpspowers.get(j));
                        }
                    }
                    menu.setChildMenu(childMenuList);
                    newMenuList.add(menu);
                }
            }

            session.setAttribute("prpspowers", newMenuList);

表结构

SpringBoot+JPA+thymeleaf 菜单分级展示

 

实例类

package com.ax.zs.springbootweb.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * Created by Hj 
 */
@Entity
@Table(name = "prpspower")
public class PRPSPOWER implements Serializable{
    @Id
    @GeneratedValue
    @Column(name="powerid")
    private String powerid;
    @Column(name="taskcode")
    private String taskcode;
    @Column(name="parentcode")
    private String parentcode;
    @Column(name="taskcname")
    private String taskcname;
    @Column(name="creatorcode")
    private String creatorcode;
    @Column(name="createtime")
    private Date createtime;
    @Column(name="updatercode")
    private String updatercode;
    @Column(name="updatetime")
    private Date updatetime;
    @Column(name="validstatus")
    private String validstatus;
    @Column(name="mlevel")
    private String mlevel;

    public String getUppermenuid() {
        return uppermenuid;
    }

    public void setUppermenuid(String uppermenuid) {
        this.uppermenuid = uppermenuid;
    }

    @Column(name="url")

    private String url;
    @Column(name="uppermenuid")
    private String uppermenuid;
    @Column(name="pagetex")
    private String pagetex;
    @Transient
    private List<PRPSPOWER> childMenu;

    public List<PRPSPOWER> getChildMenu() {
        return childMenu;
    }

    public void setChildMenu(List<PRPSPOWER> childMenu) {
        this.childMenu = childMenu;
    }

    public String getPagetex() {
        return pagetex;
    }

    public void setPagetex(String pagetex) {
        this.pagetex = pagetex;
    }



    public String getPowerid() {
        return powerid;
    }

    public void setPowerid(String powerid) {
        this.powerid = powerid;
    }

    public String getTaskcode() {
        return taskcode;
    }

    public void setTaskcode(String taskcode) {
        this.taskcode = taskcode;
    }

    public String getParentcode() {
        return parentcode;
    }

    public void setParentcode(String parentcode) {
        this.parentcode = parentcode;
    }

    public String getTaskcname() {
        return taskcname;
    }

    public void setTaskcname(String taskcname) {
        this.taskcname = taskcname;
    }

    public String getCreatorcode() {
        return creatorcode;
    }

    public void setCreatorcode(String creatorcode) {
        this.creatorcode = creatorcode;
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public String getUpdatercode() {
        return updatercode;
    }

    public void setUpdatercode(String updatercode) {
        this.updatercode = updatercode;
    }

    public Date getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(Date updatetime) {
        this.updatetime = updatetime;
    }

    public String getValidstatus() {
        return validstatus;
    }

    public void setValidstatus(String validstatus) {
        this.validstatus = validstatus;
    }

    public String getMlevel() {
        return mlevel;
    }

    public void setMlevel(String mlevel) {
        this.mlevel = mlevel;
    }

    public String getUrl() {
        return url;
    }

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

}

前端循环展示

  <ul class="sidebar-menu" id="nav-accordion">
                <li class="sub-menu" th:each="obj :${session.prpspowers}">
                    <a href="javascript:"  >
                        <i class="fa fa-desktop"></i>
                        <label th:utext="${obj.getTaskcname()}"></label>
                    </a>
                    <ul class="sub" th:each="objn :${obj.getChildMenu()}">
                        <li><a  th:href="${objn.getUrl()}" ><label th:utext="${objn.getTaskcname()}"></label></a></li>
                    </ul>
                </li>
            </ul>

页面展示

SpringBoot+JPA+thymeleaf 菜单分级展示

上一篇:Thymleaf引擎模板


下一篇:springboot+springsecurity+thymeleaf+mybatis整合