Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >基于AdminLTE的开发框架-AdminEAP

基于AdminLTE的开发框架-AdminEAP

作者头像
全栈程序员站长
发布于 2022-09-18 05:40:53
发布于 2022-09-18 05:40:53
1.4K00
代码可运行
举报
运行总次数:0
代码可运行

大家好,又见面了,我是你们的朋友全栈君。

最近在研究使用AdminLTE框架化,本文讲解使用sitemesh3使AdminLTE框架化的过程。系统架构为:SpringMVC+Spring+Hibernate+Maven+FreeMarker+Sitemesh

上图为AdminEAP首页展示目前所包含的系统功能,包含了组件集成、CURD增删改查demo、系统工具、工作流、系统权限与安全、Github源码与License、联系我们,提供了前端、后端整体解决方案,使得web开发更简单。

代码已开源,托管在github上,https://github.com/bill1012/AdminEAP

AdminEAP demo官网:http://www.admineap.com

用户列表:

用户编辑:

字典管理:

图标选择器:

回到正题,下面详细讲解sitemesh3在这个项目上的使用:(sitemesh3的配置可参考本人上篇博客)

1、Maven中引入Sitemesh3

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<dependency>
        <groupId>org.sitemesh</groupId>
	<artifactId>sitemesh</artifactId>
	<version>3.0.0</version>
</dependency>

2、web.xml中配置sitemesh3过滤器

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<filter>
	<filter-name>sitemesh</filter-name>
	<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
	<filter-name>sitemesh</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>

3、在web.xml的同级目录配置sitemesh3.xml

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
	<mapping path="/*" decorator="/decorator"></mapping>
    <mapping path="/*/*edit" exclue="true"></mapping>
<!--     <mapping path="/*/*addUpdate" exclue="true"></mapping>
    <mapping path="/*/*add" exclue="true"></mapping> 
    <mapping path="/*/*update" exclue="true"></mapping> -->
	<mapping path="/resources/*" exclue="true" />
	<mapping path="/*/nodecorator/*" exclue="true"/>
	<mapping path="/nodecorator/*" exclue="true"/>

 
	<!-- 自定义 tag 规则 -->
	<!-- Sitemesh 3 默认只提供了 body,title,head 等 tag 类型,我们可以通过实现 TagRuleBundle 扩展自定义的 tag 规则: -->
	<content-processor>
		<tag-rule-bundle class="com.cnpc.framework.tags.CSSTagRuleBundle" /> 
		<tag-rule-bundle class="com.cnpc.framework.tags.ScriptTagRuleBundle" />
	</content-processor>
	
</sitemesh>

上面定义了两个自定义标签,主要是将子页面的样式和脚本渲染到装饰页面

CSSTagRuleBundle.java

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.cnpc.framework.tags;

import org.sitemesh.SiteMeshContext;
import org.sitemesh.content.ContentProperty;
import org.sitemesh.content.tagrules.TagRuleBundle;
import org.sitemesh.content.tagrules.html.ExportTagToContentRule;
import org.sitemesh.tagprocessor.State;

public class CSSTagRuleBundle implements TagRuleBundle {

    @Override
    public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {

        defaultState.addRule("myCSS", new ExportTagToContentRule(siteMeshContext, contentProperty.getChild("myCSS"), false));

    }

    @Override
    public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {

        // TODO Auto-generated method stub

    }

}

ScriptTagRuleBundle.java

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.cnpc.framework.tags;

import org.sitemesh.SiteMeshContext;
import org.sitemesh.content.ContentProperty;
import org.sitemesh.content.tagrules.TagRuleBundle;
import org.sitemesh.content.tagrules.html.ExportTagToContentRule;
import org.sitemesh.tagprocessor.State;

public class ScriptTagRuleBundle implements TagRuleBundle {

    @Override
    public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {

        defaultState.addRule("myScript", new ExportTagToContentRule(siteMeshContext, contentProperty.getChild("myScript"), false));

    }

    @Override
    public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {

        // TODO Auto-generated method stub

    }

}

4、其中/decorator跳转的路径

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   @RequestMapping(method = RequestMethod.GET, value = "/decorator")
    public String decorator(HttpServletRequest request) {

        return "decorator";
    }

decorator.html即为“母版页”,其代码如下,请主要下面<sitemesh:write 部分

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html>  
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE |
      <span style="color:#FF0000;">
        <sitemesh:write property='title' /></span></title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- -->
    <link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico" media="screen">
    <!-- <link rel="shortcut icon" type="image/x-icon" href="${basePath}/resources/adminlte/base/img/ysd.ico" media="screen" />-->
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="${basePath}/resources/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="${basePath}/resources/adminlte/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="${basePath}/resources/adminlte/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="${basePath}/resources/adminlte/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="${basePath}/resources/adminlte/dist/css/skins/_all-skins.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!-- 加入页面的样式 -->
    <span style="color:#FF0000;">
      <sitemesh:write property='myCSS' /></span>
  </head>
  
  <body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">
      <header class="main-header">
        <!-- Logo -->
        <a href="${basePath}/main" class="logo">
          <!-- mini logo for sidebar mini 50x50 pixels -->
          <span class="logo-mini">
            <b>A</b>LT</span>
          <!-- logo for regular state and mobile devices -->
          <span class="logo-lg">
            <b>Admin</b>LTE</span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top">
          <!--此处为顶部导航功能 代码略-->
		 </nav>
      </header>
      <!-- Left side column. contains the logo and sidebar -->
      <aside class="main-sidebar">
        
          <!--此处为左部菜单功能 代码略--></aside>
      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <sitemesh:write property='body' /></div>
      <!-- /.content-wrapper -->
      <footer class="main-footer">      
            <!--此处为底部版权声明功能 代码略-->
	  </footer>
      <!-- Control Sidebar -->
      <aside class="control-sidebar control-sidebar-dark">        
          <!--此处为右侧浮动配置功能 代码略-->
	  </aside>
      <!-- /.control-sidebar -->
      <!-- Add the sidebar's background. This div must be placed immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div>
    <!-- ./wrapper -->
    <script type="text/javascript">var basePath = "${basePath}"; //给外部js文件传递路径参数
      </script>
    <!-- jQuery 2.2.0 -->
    <script src="${basePath}/resources/adminlte/plugins/jQuery/jQuery-2.2.0.min.js"></script>
    <!-- Bootstrap 3.3.6 -->
    <script src="${basePath}/resources/adminlte/bootstrap/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="${basePath}/resources/adminlte/plugins/fastclick/fastclick.js"></script>
    <!-- AdminLTE App -->
    <script src="${basePath}/resources/adminlte/dist/js/app.min.js"></script>
    <!-- Sparkline -->
    <!-- AdminLTE for demo purposes -->
    <script src="${basePath}/resources/adminlte/dist/js/demo.js"></script>
    <script type="text/javascript" src="${basePath}/resources/common/js/base.js"></script>
    <script type="text/javascript" src="${basePath}/resources/common/js/base-modal.js"></script>
    <!-- 加入页面的的脚本 -->
    <sitemesh:write property='myScript' /></body>

</html>

5、一个“子页面”的配置,如用户管理列表界面 user_list.html

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>用户列表</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.6 -->

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
<myCSS>
<link rel="stylesheet" href="${basePath}/resources/adminlte/plugins/datatables/dataTables.bootstrap.css">
<link rel="stylesheet" href="${basePath}/resources/adminlte/plugins/datatables/select.bootstrap.min.css">
<link rel="stylesheet" href="${basePath}/resources/adminlte/plugins/bootstrap-validator/dist/css/bootstrap-validator.css"/>
<link rel="stylesheet" href="${basePath}/resources/adminlte/plugins/iCheck/all.css">
<link rel="stylesheet" href="${basePath}/resources/adminlte/plugins/datepicker/datepicker3.css">
</myCSS>

</head>
<body class="hold-transition skin-blue sidebar-mini">
	<!-- Content Header (Page header) -->
	<section class="content-header">
		<h1>
			用户管理 <small>列表</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
			<li><a href="#">系统管理</a></li>
			<li class="active">用户管理</li>
		</ol>
	</section> 

	<!-- Main content -->
	<section class="content">
		<div class="row">
			<div class="col-xs-12">
				<div class="box">
					<!-- /.box-header -->
					<div class="dataTables_filter" id="searchDiv">
						<input placeholder="请输入姓名" name="name" class="form-control" type="search" likeOption="true" /> <input
							placeholder="请输入登录名" name="loginName" class="form-control" type="search" likeOption="true" />
						<div class="btn-group">
							<button type="button" class="btn btn-primary" 	action_type="search">查询</button>
							<button type="button" class="btn btn-default" action_type="reset">重置</button>
						</div>
						<div class="btn-group">
							<button type="button" class="btn btn-default" action_type="add">新增</button>
							<button type="button" class="btn btn-default" action_type="edit" >编辑</button>
							<button type="button" class="btn btn-default" action_type="delete">删除</button>
						</div>
					</div>
					<div class="box-body">
						<table id="user_table" class="table table-bordered table-striped table-hover">
						</table>
					</div>
					<!-- /.box-body -->
				</div>
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
	</section>

	<myScript> 
	    <script src="${basePath}/resources/adminlte/plugins/datatables/jquery.dataTables.js"></script>
	    <script	src="${basePath}/resources/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
		<script src="${basePath}/resources/common/js/dataTables.js"></script>
		<!-- form -->
		<script src="${basePath}/resources/adminlte/plugins/bootstrap-validator/dist/js/bootstrap-validator.js"></script>
		<script src="${basePath}/resources/adminlte/plugins/iCheck/icheck.min.js"></script>
		<script src="${basePath}/resources/adminlte/plugins/datepicker/bootstrap-datepicker.js"></script>
		<script>  
			//tableId,queryId,conditionContainer
			var userTable;
			var winId="userWin";
			$(function() { 
				//init table and fill data
				userTable = new CommonTable("user_table", "user_list", "searchDiv");
				
				//button event
				$('button[action_type]').click(function() {
					var action = $(this).attr('action_type');
					var rowId=userTable.getSelectedRowId();
					switch (action) {
					case 'add':
                        modals.openWin({
                        	winId:winId,
                        	title:'新增用户',
                        	top:'auto',
                        	width:'900px',
                        	url:basePath+"/user/edit"
                        	/*, hideFunc:function(){
                        		modals.info("hide me");
                        	},
                        	showFunc:function(){
                        		modals.info("show me");
                        	} */
                        });                        
						break;
					case 'edit':
						if(!rowId){
							modals.info('请选择要编辑的行');
							return false;
						}
						modals.openWin({
                        	winId:winId,
                        	title:'编辑用户【'+userTable.getSelectedRowData().name+'】',
                        	top:'auto',
                        	width:'900px',
                        	url:basePath+"/user/edit?id="+rowId
                        }); 
					   break;
					case 'delete':
						if(!rowId){
							modals.info('请选择要删除的行');
							return false;
						}
						modals.confirm("是否要删除该行数据?",function(){
							ajaxPost(basePath+"/user/delete/"+rowId,null,function(data){
								if(data.success){
									//modals.correct("已删除该数据");
									userTable.reloadRowData();
								}
							});
						})
						break;
					}

				});
				//form_init();
			})
			
		
		</script> 
    </myScript>
</body>
</html>

以上过程完成了AdminLTE的框架化,但是存在一个性能问题,即每次需要访问/decorator路径,会重置顶部导航和左侧菜单,导致不能记住顶部导航和左侧当前菜单。后续可能不会使用Sitemesh3,可能会用jquery 的load方法。

当然有人说,sitemesh3太折腾了,用iframe不就可以吗?确实可以,但iframe的高度自适应的问题是在太恶心了,也存在一些其他问题。

代码已开源,托管在github上,https://github.com/bill1012/AdminEAP

demo详见 http://www.admineap.comdemo详见 http://www.admineap.comdemo详见 http://www.admineap.comdemo详见 http://www.admineap.comdemo详见 http://www.admineap.comdemo详见 http://www.admineap.comdemo详见 http://www.admineap.com

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164536.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Python开发物联网数据分析平台---最近一年
image.png image.png 前端页面year.html代码如下: {% extends "base.html" %} {% block css %} <!-- DataTables --> <link rel="stylesheet" href="plugins/datatables-bs4/css/dataTables.bootstrap4.css"> {% end %} {% block body %} <div class="content-wrapper" data-menu="
MiaoGIS
2019/11/22
8910
Python开发物联网数据分析平台---最近一年
adminLTE的介绍
adminLTE的官方网站:adminLTE官方网站 和github:adminLTE的github
全栈程序员站长
2022/09/19
2.8K0
前端框架AdminLTE
https://github.com/almasaeed2010/AdminLTE/releases
全栈程序员站长
2022/09/18
2.5K0
前端框架AdminLTE
UI框架——后台管理系统模板
仪表盘演示:https://3vshej.cn/AdminLTE/AdminLTE-2.4/ 源代码下载:https://3vshej.cn/AdminLTE/ 使用文档:https://itheima2017.gitbooks.io/adminlte2-itheima-doc/ 由于AdminLTE仪表盘代码过于复杂,因为组件太多,要自己灵活的使用要花很多时间了解源代码,并了解起框架的结构。因此,自己根据自己的想法,注释并且简洁化的修改了这个模板,可以根据自己的需求很灵活的使用起来。 修改后的界面如下
不愿意做鱼的小鲸鱼
2022/09/26
7.4K0
UI框架——后台管理系统模板
adminlte ajax,AdminLTE
AdminLTE uses all of Bootstrap 3 components. It’s a good start to review
全栈程序员站长
2022/09/18
3950
使用ABP打造SAAS系统(2)——前端框架选择[通俗易懂]
  作者用过的前端框架不少,曾经还在一个项目中同时使用两套框架控件(年少无知、效率特慢),所以可供选择的前端框架有不少:
全栈程序员站长
2022/11/04
2.5K0
使用ABP打造SAAS系统(2)——前端框架选择[通俗易懂]
Django——图书管理系统(五)
本文接着来给网页添加bootstrap样式。首先,需要在settings.py文件中加入静态文件的配置,如下所示:
zy010101
2021/01/21
5530
大型项目技术栈第一讲 Vue.js的使用
Vue.js是一个构建数据驱动的 web 界面的渐进式框架。Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件。它不仅易于上手,还便于与第三方库或既有项目整合。
易兮科技
2020/09/27
5.1K0
大型项目技术栈第一讲  Vue.js的使用
网站搭建-django-学习成绩管理-12-卡片
系统:Windows 10 语言版本:Anaconda3-4.3.0.1-Windows-x86_64 编辑器:JetBrains PyCharm Community Edition 2018.2.2 x64 Django:2.1.4 Python:3.6.0
zishendianxia
2021/05/13
1.1K0
网站搭建-django-学习成绩管理-12-卡片
基于bootstrap的web登陆实例
前情提要 之前已经搭好的springMVC+myBatis项目骨架,详情请看–>传送门。
bear_fish
2018/09/19
3.2K0
基于bootstrap的web登陆实例
E008Web开发框架-Bootstrap
第一步:下载Bootstrap,中文官网网址https://www.bootcss.com/;
訾博ZiBo
2025/01/06
880
快速使用layui和ssm开发
大概就这么多,本地导入static文件后,直接复制上面的index首页就可以开始进行layui开发了,很方便。
废江_小江
2022/09/05
6050
《SSM篇》《整合SSM+Mybitas-plus+shiro+quartz容灾项目登录篇》
一、环境搭建 1.配置pom <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.
2020/10/29
8890
模仿天猫实战【SSM版】——后台开发
上一篇文章链接:模仿天猫实战【SSM版】——项目起步 后台需求分析 在开始码代码之前,还是需要先清楚自己要做什么事情,后台具体需要实现哪些功能: 注意: 订单、用户、订单、推荐链接均不提供增删的
我没有三颗心脏
2018/06/13
2.2K0
Django的主体页面抽取(七)
在潦草的完成了注册与登录之后,下面开始编写平台的主体部分了。 忘记密码和恢复密码部分在最后完善的时候补上。
zx钟
2019/07/19
7830
引入 SB Admin 2 作为后台管理系统主题
完全前端基本功能之后,接下来,我们来构建这个 PHP 博客项目后台管理系统,主要包含登录认证,仪表盘页面,专辑、文章的创建、修改和删除,以及消息后台查看等功能。最终后台界面效果图如下(依次是专辑列表页、发布文章页、消息列表页):
学院君
2020/09/28
4.3K0
引入 SB Admin 2 作为后台管理系统主题
springboot开发之显示员工信息
在entities包中:有Employee.java、Department.java
西西嘛呦
2020/08/26
2.8K0
springboot开发之显示员工信息
前端开发---异步上传文件
有一个名为ajaxFileUpload的JQuery插件可以利用iframe来实现前端页面中异步上传文件。
MiaoGIS
2020/11/25
1.5K0
前端开发---异步上传文件
Bootstrap3-导航条[通俗易懂]
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/129314.html原文链接:https://javaforall.cn
全栈程序员站长
2022/07/29
2.6K0
Python开发物联网数据分析平台---web框架
前端使用Bootstrap主题框架AdminLTE,后台使用python语言的tornado作为web框架。利用tornado的模板作为主要的动态页面生成方式,以及巧妙使用模板将json数据渲染到页面hidden元素的值,然后在js中直接用eval函数计算隐藏域的值来生成图表JavaScript插件所需的json数据来生成页面中相应的可视化图表。
MiaoGIS
2019/11/01
3.2K0
Python开发物联网数据分析平台---web框架
相关推荐
Python开发物联网数据分析平台---最近一年
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验