基于AdminLTE的开发框架-AdminEAP

基于AdminLTE的开发框架-AdminEAP系统架构为:SpringMVC+Spring+Hibernate+Maven+FreeMarker+Sitemesh上图为AdminEAP首页展

大家好,欢迎来到IT知识分享网。

基于AdminLTE的开发框架-AdminEAP

最近在研究使用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

用户列表:

基于AdminLTE的开发框架-AdminEAP

用户编辑:

基于AdminLTE的开发框架-AdminEAP

字典管理:

基于AdminLTE的开发框架-AdminEAP

图标选择器:

基于AdminLTE的开发框架-AdminEAP

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

1、Maven中引入Sitemesh3

  1. <dependency>
  2. <groupId>org.sitemesh</groupId>
  3. <artifactId>sitemesh</artifactId>
  4. <version>3.0.0</version>
  5. </dependency>

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

  1. <filter>
  2. <filter-name>sitemesh</filter-name>
  3. <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
  4. </filter>
  5. <filter-mapping>
  6. <filter-name>sitemesh</filter-name>
  7. <url-pattern>/*</url-pattern>
  8. </filter-mapping>

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

  1. <?xml version=”1.0″ encoding=”UTF-8″?>
  2. <sitemesh>
  3. <mapping path=”/*” decorator=”/decorator”></mapping>
  4. <mapping path=”/*/*edit” exclue=”true”></mapping>
  5. <!– <mapping path=”/*/*addUpdate” exclue=”true”></mapping>
  6. <mapping path=”/*/*add” exclue=”true”></mapping>
  7. <mapping path=”/*/*update” exclue=”true”></mapping> –>
  8. <mapping path=”/resources/*” exclue=”true” />
  9. <mapping path=”/*/nodecorator/*” exclue=”true”/>
  10. <mapping path=”/nodecorator/*” exclue=”true”/>
  11. <!– 自定义 tag 规则 –>
  12. <!– Sitemesh 3 默认只提供了 body,title,head 等 tag 类型,我们可以通过实现 TagRuleBundle 扩展自定义的 tag 规则: –>
  13. <content-processor>
  14. <tag-rule-bundle class=”com.cnpc.framework.tags.CSSTagRuleBundle” />
  15. <tag-rule-bundle class=”com.cnpc.framework.tags.ScriptTagRuleBundle” />
  16. </content-processor>
  17. </sitemesh>

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

CSSTagRuleBundle.java

  1. package com.cnpc.framework.tags;
  2. import org.sitemesh.SiteMeshContext;
  3. import org.sitemesh.content.ContentProperty;
  4. import org.sitemesh.content.tagrules.TagRuleBundle;
  5. import org.sitemesh.content.tagrules.html.ExportTagToContentRule;
  6. import org.sitemesh.tagprocessor.State;
  7. public class CSSTagRuleBundle implements TagRuleBundle {
  8. @Override
  9. public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
  10. defaultState.addRule(“myCSS”, new ExportTagToContentRule(siteMeshContext, contentProperty.getChild(“myCSS”), false));
  11. }
  12. @Override
  13. public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
  14. // TODO Auto-generated method stub
  15. }
  16. }

ScriptTagRuleBundle.java

  1. package com.cnpc.framework.tags;
  2. import org.sitemesh.SiteMeshContext;
  3. import org.sitemesh.content.ContentProperty;
  4. import org.sitemesh.content.tagrules.TagRuleBundle;
  5. import org.sitemesh.content.tagrules.html.ExportTagToContentRule;
  6. import org.sitemesh.tagprocessor.State;
  7. public class ScriptTagRuleBundle implements TagRuleBundle {
  8. @Override
  9. public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
  10. defaultState.addRule(“myScript”, new ExportTagToContentRule(siteMeshContext, contentProperty.getChild(“myScript”), false));
  11. }
  12. @Override
  13. public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
  14. // TODO Auto-generated method stub
  15. }
  16. }

4、其中/decorator跳转的路径

  1. @RequestMapping(method = RequestMethod.GET, value = “/decorator”)
  2. public String decorator(HttpServletRequest request) {
  3. return “decorator”;
  4. }

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

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=”utf-8″>
  5. <meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
  6. <title>AdminLTE |
  7. <span style=”color:#FF0000;”>
  8. <sitemesh:write property=’title’ /></span></title>
  9. <!– Tell the browser to be responsive to screen width –>
  10. <meta content=”width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no” name=”viewport”>
  11. <!– –>
  12. <link rel=”shortcut icon” type=”image/ico” href=”http://www.datatables.net/favicon.ico” media=”screen”>
  13. <!– <link rel=”shortcut icon” type=”image/x-icon” href=”${basePath}/resources/adminlte/base/img/ysd.ico” media=”screen” />–>
  14. <!– Bootstrap 3.3.6 –>
  15. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/bootstrap/css/bootstrap.min.css”>
  16. <!– Font Awesome –>
  17. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/css/font-awesome.min.css”>
  18. <!– Ionicons –>
  19. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/css/ionicons.min.css”>
  20. <!– Theme style –>
  21. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/dist/css/AdminLTE.min.css”>
  22. <!– AdminLTE Skins. Choose a skin from the css/skins folder instead of downloading all of them to reduce the load. –>
  23. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/dist/css/skins/_all-skins.min.css”>
  24. <!– HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries –>
  25. <!– WARNING: Respond.js doesn’t work if you view the page via file:// –>
  26. <!–[if lt IE 9]>
  27. <script src=”https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js”></script>
  28. <script src=”https://oss.maxcdn.com/respond/1.4.2/respond.min.js”></script>
  29. <![endif]–>
  30. <!– 加入页面的样式 –>
  31. <span style=”color:#FF0000;”>
  32. <sitemesh:write property=’myCSS’ /></span>
  33. </head>
  34. <body class=”hold-transition skin-blue sidebar-mini”>
  35. <div class=”wrapper”>
  36. <header class=”main-header”>
  37. <!– Logo –>
  38. <a href=”${basePath}/main” class=”logo”>
  39. <!– mini logo for sidebar mini 50×50 pixels –>
  40. <span class=”logo-mini”>
  41. <b>A</b>LT</span>
  42. <!– logo for regular state and mobile devices –>
  43. <span class=”logo-lg”>
  44. <b>Admin</b>LTE</span>
  45. </a>
  46. <!– Header Navbar: style can be found in header.less –>
  47. <nav class=”navbar navbar-static-top”>
  48. <!–此处为顶部导航功能 代码略–>
  49. </nav>
  50. </header>
  51. <!– Left side column. contains the logo and sidebar –>
  52. <aside class=”main-sidebar”>
  53. <!–此处为左部菜单功能 代码略–></aside>
  54. <!– Content Wrapper. Contains page content –>
  55. <div class=”content-wrapper”>
  56. <sitemesh:write property=’body’ /></div>
  57. <!– /.content-wrapper –>
  58. <footer class=”main-footer”>
  59. <!–此处为底部版权声明功能 代码略–>
  60. </footer>
  61. <!– Control Sidebar –>
  62. <aside class=”control-sidebar control-sidebar-dark”>
  63. <!–此处为右侧浮动配置功能 代码略–>
  64. </aside>
  65. <!– /.control-sidebar –>
  66. <!– Add the sidebar’s background. This div must be placed immediately after the control sidebar –>
  67. <div class=”control-sidebar-bg”></div>
  68. </div>
  69. <!– ./wrapper –>
  70. <script type=”text/javascript”>var basePath = “${basePath}”; //给外部js文件传递路径参数
  71. </script>
  72. <!– jQuery 2.2.0 –>
  73. <script src=”${basePath}/resources/adminlte/plugins/jQuery/jQuery-2.2.0.min.js”></script>
  74. <!– Bootstrap 3.3.6 –>
  75. <script src=”${basePath}/resources/adminlte/bootstrap/js/bootstrap.min.js”></script>
  76. <!– FastClick –>
  77. <script src=”${basePath}/resources/adminlte/plugins/fastclick/fastclick.js”></script>
  78. <!– AdminLTE App –>
  79. <script src=”${basePath}/resources/adminlte/dist/js/app.min.js”></script>
  80. <!– Sparkline –>
  81. <!– AdminLTE for demo purposes –>
  82. <script src=”${basePath}/resources/adminlte/dist/js/demo.js”></script>
  83. <script type=”text/javascript” src=”${basePath}/resources/common/js/base.js”></script>
  84. <script type=”text/javascript” src=”${basePath}/resources/common/js/base-modal.js”></script>
  85. <!– 加入页面的的脚本 –>
  86. <sitemesh:write property=’myScript’ /></body>
  87. </html>

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

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=”utf-8″>
  5. <meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
  6. <title>用户列表</title>
  7. <!– Tell the browser to be responsive to screen width –>
  8. <meta content=”width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no” name=”viewport”>
  9. <!– Bootstrap 3.3.6 –>
  10. <!– HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries –>
  11. <!– WARNING: Respond.js doesn’t work if you view the page via file:// –>
  12. <!–[if lt IE 9]>
  13. <script src=”https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js”></script>
  14. <script src=”https://oss.maxcdn.com/respond/1.4.2/respond.min.js”></script>
  15. <![endif]–>
  16. <myCSS>
  17. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/plugins/datatables/dataTables.bootstrap.css”>
  18. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/plugins/datatables/select.bootstrap.min.css”>
  19. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/plugins/bootstrap-validator/dist/css/bootstrap-validator.css”/>
  20. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/plugins/iCheck/all.css”>
  21. <link rel=”stylesheet” href=”${basePath}/resources/adminlte/plugins/datepicker/datepicker3.css”>
  22. </myCSS>
  23. </head>
  24. <body class=”hold-transition skin-blue sidebar-mini”>
  25. <!– Content Header (Page header) –>
  26. <section class=”content-header”>
  27. <h1>
  28. 用户管理 <small>列表</small>
  29. </h1>
  30. <ol class=”breadcrumb”>
  31. <li><a href=”#”><i class=”fa fa-dashboard”></i> 首页</a></li>
  32. <li><a href=”#”>系统管理</a></li>
  33. <li class=”active”>用户管理</li>
  34. </ol>
  35. </section>
  36. <!– Main content –>
  37. <section class=”content”>
  38. <div class=”row”>
  39. <div class=”col-xs-12″>
  40. <div class=”box”>
  41. <!– /.box-header –>
  42. <div class=”dataTables_filter” id=”searchDiv”>
  43. <input placeholder=”请输入姓名” name=”name” class=”form-control” type=”search” likeOption=”true” /> <input
  44. placeholder=”请输入登录名” name=”loginName” class=”form-control” type=”search” likeOption=”true” />
  45. <div class=”btn-group”>
  46. <button type=”button” class=”btn btn-primary” action_type=”search”>查询</button>
  47. <button type=”button” class=”btn btn-default” action_type=”reset”>重置</button>
  48. </div>
  49. <div class=”btn-group”>
  50. <button type=”button” class=”btn btn-default” action_type=”add”>新增</button>
  51. <button type=”button” class=”btn btn-default” action_type=”edit” >编辑</button>
  52. <button type=”button” class=”btn btn-default” action_type=”delete”>删除</button>
  53. </div>
  54. </div>
  55. <div class=”box-body”>
  56. <table id=”user_table” class=”table table-bordered table-striped table-hover”>
  57. </table>
  58. </div>
  59. <!– /.box-body –>
  60. </div>
  61. </div>
  62. <!– /.col –>
  63. </div>
  64. <!– /.row –>
  65. </section>
  66. <myScript>
  67. <script src=”${basePath}/resources/adminlte/plugins/datatables/jquery.dataTables.js”></script>
  68. <scriptsrc=”${basePath}/resources/adminlte/plugins/datatables/dataTables.bootstrap.min.js”></script>
  69. <script src=”${basePath}/resources/common/js/dataTables.js”></script>
  70. <!– form –>
  71. <script src=”${basePath}/resources/adminlte/plugins/bootstrap-validator/dist/js/bootstrap-validator.js”></script>
  72. <script src=”${basePath}/resources/adminlte/plugins/iCheck/icheck.min.js”></script>
  73. <script src=”${basePath}/resources/adminlte/plugins/datepicker/bootstrap-datepicker.js”></script>
  74. <script>
  75. //tableId,queryId,conditionContainer
  76. var userTable;
  77. var winId=”userWin”;
  78. $(function() {
  79. //init table and fill data
  80. userTable = new CommonTable(“user_table”, “user_list”, “searchDiv”);
  81. //button event
  82. $(‘button[action_type]’).click(function() {
  83. var action = $(this).attr(‘action_type’);
  84. var rowId=userTable.getSelectedRowId();
  85. switch (action) {
  86. case ‘add’:
  87. modals.openWin({
  88. winId:winId,
  89. title:’新增用户’,
  90. top:’auto’,
  91. width:’900px’,
  92. url:basePath+”/user/edit”
  93. /*, hideFunc:function(){
  94. modals.info(“hide me”);
  95. },
  96. showFunc:function(){
  97. modals.info(“show me”);
  98. } */
  99. });
  100. break;
  101. case ‘edit’:
  102. if(!rowId){
  103. modals.info(‘请选择要编辑的行’);
  104. return false;
  105. }
  106. modals.openWin({
  107. winId:winId,
  108. title:’编辑用户【’+userTable.getSelectedRowData().name+’】’,
  109. top:’auto’,
  110. width:’900px’,
  111. url:basePath+”/user/edit?id=”+rowId
  112. });
  113. break;
  114. case ‘delete’:
  115. if(!rowId){
  116. modals.info(‘请选择要删除的行’);
  117. return false;
  118. }
  119. modals.confirm(“是否要删除该行数据?”,function(){
  120. ajaxPost(basePath+”/user/delete/”+rowId,null,function(data){
  121. if(data.success){
  122. //modals.correct(“已删除该数据”);
  123. userTable.reloadRowData();
  124. }
  125. });
  126. })
  127. break;
  128. }
  129. });
  130. //form_init();
  131. })
  132. </script>
  133. </myScript>
  134. </body>
  135. </html>

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

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

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

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/61536.html

(0)
上一篇 2024-05-14 16:45
下一篇 2024-07-02 14:00

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信