基于springboot+bootstrap+mysql+redis搭建一套完整的权限架构【六】【引入bootstrap前端框架】
2017年12月11日 10:19:24 笨_鸟_不_会_飞 阅读数:12574
版权声明:本文为博主原创文章,未经博主容许不得转载。 https://blog.csdn.net/linzhefeng89/article/details/78752658
bootstrap是目前最受欢迎的前端框架,bootstrap是基于HTML、CSS、JAVASCRIPT的,她界面美光、代码简介、开发灵活,所以深受开发者的喜好,本文中用的bootstrap框架的版本是3.0以上的版本,若你们对bootstrap框架有兴趣能够直接到她的官方网站直接查阅相应的文档信息,官网地址:http://getbootstrap.com/。css
因为bootstrap实际上咱们在谷歌的时候会发现已经有大量的大神已经基于bootstrap给咱们搭建好了各类各样的DEMO,所以咱们彻底没有必要本身去闭门造车,咱们直接拿着前人写好的DEMO咱们本身修改下就能够变成咱们本身的东西,因为深刻bootstrap的话那就是要一个专题来说解了,此处主要讲解的是如何基于bootstrap来搭建一套完整的权限架构所以就再也不此处深刻的去讲解该框架,只要你们跑过一遍代码能够懂得如何使用就行了,若像更深刻的去学习,那么你们去网上搜索下资料,上面有大量的资料供你们学习。html
首先基于咱们的第五章的工程咱们将咱们事先已经封装好的bootstrap脚本引入到咱们现有的工程,你们若须要该快的代码,请你们直接在文章的末尾去github上本身去拿此块封装的代码,目录以下:前端

到此咱们的bootstraop框架引入完成,那么基于bootstrap框架咱们如今开始开发属于咱们的第一个bootstrap页面登录页,打开咱们的templates文件在底下找到咱们login.html页面,进行从新的编辑该页面代码以下:java
-
-
<html xmlns:th="http://www.thymeleaf.org">
-
-
<meta content="text/html;charset=UTF-8"/>
-
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
-
-
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
<div class="starter-template">
-
<p th:if="${param.logout}" class="bg-warning">已成功注销</p>
-
<p th:if="${param.error}" th:text="${session.SPRING_SECURITY_LAST_EXCEPTION.message}=='Bad credentials'?'帐号/密码错误!':${session.SPRING_SECURITY_LAST_EXCEPTION.message}" class="bg-danger">
-
-
-
-
<form name="form" th:action="@{/login}" action="/login" method="POST">
-
-
<label for="username">帐号</label>
-
<input type="text" class="form-control" name="username" id="username" value="" placeholder="帐号" />
-
-
-
<label for="password">密码</label>
-
<input type="password" class="form-control" name="password" id="password" placeholder="密码" />
-
-
<input type="submit" id="login" value="Login" class="btn btn-primary" />
-
-
-
-
-
-
-
从新加载并运行咱们的程序咱们会看到咱们全新的页面效果以下所示:

到此咱们的登录的首页已经完成了,接着咱们再开发咱们登录成功之后的主页main.html,在咱们编写咱们的主页的时候,咱们须要从新设计下咱们的数据库,所以咱们现有的表结构没法支撑起来咱们的整个业务系统,所以咱们从新设计了咱们的数据库以下图:mysql

接着咱们直接生成咱们的数据库执行脚本,并在咱们的数据库中执行,同时使用咱们上一章开发的工具咱们来快速生成咱们的代码,并根据咱们的权限架构来修改咱们的代码,如下是通过修改之后的代码的结构:jquery

在咱们的工程中有一些咱们常常用到的CSS或者js 咱们并不想每一个页面都进行一次引用,所以咱们新建一个全局的引用到咱们的工程(在templates底下新建一个文件夹include同时建立includebase.html文件)中以下:git
-
<html xmlns:th="http://www.thymeleaf.org">
-
<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
-
<link th:href="@{/css/bootstrap-table.css}" rel="stylesheet"/>
-
<link th:href="@{/font-awesome/css/font-awesome.min.css}" rel="stylesheet"/>
-
<link th:href="@{/css/bootstrap-datetimepicker.css}" rel="stylesheet"/>
-
<link th:href="@{/css/bootstrapValidator.min.css}" rel="stylesheet"/>
-
<link th:href="@{/css/fileinput.css}" rel="stylesheet"/>
-
<link th:href="@{/css/fileinput-rtl.css}" rel="stylesheet"/>
-
<link th:href="@{/css/theme.css}" rel="stylesheet"/>
-
<link th:href="@{/css/zTreeStyle/metro.css}" rel="stylesheet"/>
-
-
-
<script th:src="@{/js/sockjs.min.js}"></script>
-
<script th:src="@{/js/stomp.min.js}"></script>
-
<script th:src="@{/js/jquery.js}"></script>
-
<script th:src="@{/js/distpicker/distpicker.data.js}"></script>
-
<script th:src="@{/js/distpicker/distpicker.js}"></script>
-
<script th:src="@{/js/websocket/socketUtil.js}"></script>
-
<script th:src="@{/js/bootstrap.min.js}"></script>
-
<script th:src="@{/js/bootstrap/nav/nav.js}"></script>
-
<script th:src="@{/js/bootstrap/tab/bootstrap-tab.js}"></script>
-
<script th:src="@{/js/bootstrap/tree/tree.js}"></script>
-
<script th:src="@{/js/bootstrap/alert/alert.js}"></script>
-
<script th:src="@{/js/bootstrap/table/bootstrap-table.js}"></script>
-
<script th:src="@{/js/bootstrap/date/bootstrap-datetimepicker.js}"></script>
-
<script th:src="@{/js/bootstrap/validator/bootstrapValidator.min.js}"></script>
-
<script th:src="@{/js/bootstrap/upload/fileinput.min.js}"></script>
-
<script th:src="@{/js/bootstrap/upload/plugins/sortable.js}"></script>
-
<script th:src="@{/js/bootstrap/upload/locales/zh.js}"></script>
-
<script th:src="@{/js/bootstrap/upload/theme.js}"></script>
-
<script th:src="@{/js/bootstrap/ztree/jquery.ztree.all-3.5.min.js}"></script>
-
<script th:src="@{/js/bootstrap/checkbox/checkbox.js}"></script>
-
<script th:src="@{/js/ajaxutil/ajaxUtil.js}"></script>
-
<script th:src="@{/js/dict/dictUtil.js}"></script>
-
<script th:src="@{/js/bootstrap/date/date.prototype.format.js}"></script>
-
<script th:src="@{/js/bootstrap/util/number.pick.util.js}"></script>
-
-
经过以上的代码的快速生成、修改以及配置咱们这才能够正式开发咱们的登录成功之后的首页,首页代码以下:
-
<html xmlns:th="http://www.thymeleaf.org"
-
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
-
<head th:include="include/includebase"></head>
-
<link th:href="@{css/sb-admin.css}" rel="stylesheet"/>
-
<script th:inline="javascript">
-
-
// 页面加载完成之后开启websocket的链接
-
var options = new Array();
-
options.sockurl = '/ricky-websocket';
-
options.stompClienturl = '/ricky/topic/greetings';
-
options.login = [[${#authentication.name}]];
-
options.success = function(greeting){
-
var r = eval("("+JSON.parse(greeting.body).content+")")
-
-
// $("#greetings").append("
<tr><td>" + JSON.parse(greeting.body).content + "</td></tr>");
-
-
$.fn.socketConnect(options);
-
-
$.fn.bootstrapNav({index:'main',navTitle:'XXXX管理系统'});
-
-
$("#tabContainer").tabs({
-
-
-
-
-
-
-
-
-
-
-
$.fn.bootstrapTree({url:"/user/mainTree",treeId:'menu_tree',tabId:"tabContainer"});
-
$.fn.dictUtil("/dict/loadDict");
-
-
-
-
-
-
-
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
-
-
<div class="navbar-header" id="navbar_header">
-
-
-
-
<ul class="nav navbar-right top-nav">
-
-
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-envelope"></i> <b class="caret"></b></a>
-
<ul class="dropdown-menu message-dropdown">
-
<li class="message-preview">
-
-
-
-
<img class="media-object" src="http://placehold.it/50x50" alt="" />
-
-
-
<h5 class="media-heading"><strong>John Smith</strong>
-
-
<p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
-
<p>Lorem ipsum dolor sit amet, consectetur...</p>
-
-
-
-
-
<li class="message-preview">
-
-
-
-
<img class="media-object" src="http://placehold.it/50x50" alt="" />
-
-
-
<h5 class="media-heading"><strong>John Smith</strong>
-
-
<p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
-
<p>Lorem ipsum dolor sit amet, consectetur...</p>
-
-
-
-
-
<li class="message-preview">
-
-
-
-
<img class="media-object" src="http://placehold.it/50x50" alt="" />
-
-
-
<h5 class="media-heading"><strong>John Smith</strong>
-
-
<p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
-
<p>Lorem ipsum dolor sit amet, consectetur...</p>
-
-
-
-
-
<li class="message-footer">
-
<a href="#">Read All New Messages</a>
-
-
-
-
-
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> <font th:text="${#authentication.name}"></font> <b class="caret"></b></a>
-
<ul class="dropdown-menu">
-
-
<a href="#" ><i class="fa fa-fw fa-gear"></i> 修改密码 </a>
-
-
<li class="divider"></li>
-
-
<a href="/logout" ><i class="fa fa-fw fa-power-off"></i>退 出</a>
-
-
-
-
-
-
<div class="collapse navbar-collapse navbar-ex1-collapse">
-
<ul class="nav navbar-nav side-nav" id="menu_tree">
-
-
-
-
-
-
<div id="page-wrapper" style="border-radius:5px 5px 0 0;">
-
<div id="tabContainer"></div>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
那么到此处咱们已经完成了整个系统的基础架构的百分80的开发工做了,那么剩下的就是开发咱们相应的功能模块。github
本章代码的GitHub地址:https://github.com/185594-5-27/csdndemo/tree/master-base-treeweb
上一篇文章地址:基于springboot+bootstrap+mysql+redis搭建一套完整的权限架构【五】【编写基础代码快速生成工具】
下一篇文章地址:基于springboot+bootstrap+mysql+redis搭建一套完整的权限架构【七】【菜单维护模块】