python222网站实战(SpringBoot+SpringSecurity+MybatisPlus+thymeleaf+layui)-主页设计Menu动态菜单模块实现
锋哥原创的Springboot+Layui python222网站实战:
CREATE TABLE `t_menu` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20) DEFAULT NULL,
`url` VARCHAR(500) DEFAULT NULL,
`color` VARCHAR(20) DEFAULT NULL,
`strong` BIT(1) DEFAULT b'0',
`sort` INT(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
/*Data for the table `t_menu` */
INSERT INTO `t_menu`(`id`,`name`,`url`,`color`,`strong`,`sort`) VALUES (1,'首页','/','black','\0',1),(2,'课程','/course/list','black','\0',2),(3,'Java全栈学习路线图','/article/1','black','',3),(6,'关于锋哥','/article/14','#e11717','',6),(9,'java1234门徒服务','/article/5','#000000','',5),(11,'VIP活动特价','http://www.java1234.com/vip.html','#f50606','',4);
通过MybatisX插件生成代码
缓存里获取menuList
common下面新建menu.html
<meta charset="UTF-8">
<div id="m">
<a href="/" class="logo" ></a>
<ul class="nav">
<li th:each="menu:${application.menuList}"><a th:href="${menu.url}" th:style="'color:'+${menu.color}+';font-weight:'+${menu.strong==true?'bold':'normal'}" th:text="${menu.name}"></a></li>
</ul>
<div class="searchAndLogin">
<div class="search d7">
<form action="/search/1" method="post">
<input type="text" name="keyWord" placeholder="搜索从这里开始..." autocomplete="off" >
<button type="submit"></button>
</form>
</div>
</div>
</div>