Layui 后台加载菜单栏名称以及url的例子
作者:newHESH
今天小编就为大家分享一篇Layui 后台加载菜单栏名称以及url的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
一个小小的demo,演示从Controller层传参到视图,有使用到SpringMvc、jstl标签
效果图:
1、testdemo.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 --> <link rel="stylesheet" href="${ pageContext.request.contextPath }/layui/css/layui.css" rel="external nofollow" media="all"> </head> <body> <ul class="layui-nav layui-nav-tree" lay-filter="test"> <!-- 侧边导航: <ul class="layui-nav layui-nav-tree layui-nav-side"> --> <li class="layui-nav-item layui-nav-itemed"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" >默认展开</a> <dl class="layui-nav-child"> <c:forEach var="v" items="${itemname1[0]}" varStatus="i"> <dd> <a href="${pageContext.request.contextPath}${itemname1[1].get(i.count-1)}" rel="external nofollow" rel="external nofollow" >${itemname1[0].get(i.count-1)}</a> </dd> </c:forEach> </dl></li> <li class="layui-nav-item"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" >解决方案</a> <dl class="layui-nav-child"> <dd> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" >后台模版</a> <dl class="layui-nav-child"> <c:forEach var="s" items="${itemname2[0]}" varStatus="i"> <dd> <a href="${pageContext.request.contextPath}${itemname2[1].get(i.count-1)}" rel="external nofollow" >${itemname2[0].get(i.count-1)}</a> </dd> </c:forEach> </dl> </dd> <dd> <c:forEach var="v" items="${itemname1[0]}" varStatus="i"> <dd> <a href="${pageContext.request.contextPath}${itemname1[1].get(i.count-1)}" rel="external nofollow" rel="external nofollow" >${itemname1[0].get(i.count-1)}</a> </dd> </c:forEach> </dd> </dl></li> <li class="layui-nav-item"><a href="">产品</a></li> <li class="layui-nav-item"><a href="">大数据</a></li> </ul> <!-- 注意:如果你直接复制所有代码到本地,上述js路径需要改成你本地的 --> <script src="layui/layui.js"></script> <script> layui.use('element', function() { var element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块 //监听导航点击 element.on('nav(demo)', function(elem) { layer.msg(elem.text()); }); }); </script> </body> </html>
2、TestController.java
@Controller @Scope(value = "prototype") @RequestMapping("/") public class TestController { @RequestMapping(value="/testdemo") //从上一个页面跳转过来,如果只是看看效果直接输入http://localhost:8080/项目名/testdemo public String Test(Model model) { List<List<String>>list1=new ArrayList(); List<String> l1 = Arrays.asList("二级菜单1","二级菜单2","二级菜单3");//模拟获得数据 List<String> l2 = Arrays.asList("/url1","/url2","/url3"); List<List<String>>list2=new ArrayList(); List<String> l3 = Arrays.asList("三级菜单1","三级菜单2","三级菜单3","三级菜单4");//模拟获得数据 List<String> l4 = Arrays.asList("/url1","/url2","/url3","/url4"); list1.add(l1); list1.add(l2); list2.add(l3); list2.add(l4); model.addAttribute("itemname1",list1); model.addAttribute("itemname2",list2); return"testdemo"; } }
以上这篇Layui 后台加载菜单栏名称以及url的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。