在前臺的佈置中已經進行了數據庫的建立,在後臺中我使用的數據庫是同一個,數據庫中一樣是四張表javascript
命名爲:QSSY_Backcss
項目使用到的jar包,並進行導入項目中html
導入jar包後記得全選單擊右鍵Build Pathjava
在src中建這樣的幾個包:mysql
初始時頁面顯示的數據都是靜態的jquery
效果圖:web
index.html:spring
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>泉師釋疑後臺登陸</title> <meta name="renderer" content="webkit|ie-comp|ie-stand"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" /> <meta http-equiv="Cache-Control" content="no-siteapp" /> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> <link rel="stylesheet" href="./css/font.css"> <link rel="stylesheet" href="./css/xadmin.css"> <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script src="./lib/layui/layui.js" charset="utf-8"></script> <script type="text/javascript" src="./js/xadmin.js"></script> </head> <body> <!-- 頂部開始 --> <div class="container"> <div class="logo"><a href="./index.html">泉師釋疑後臺</a></div> <div class="left_open"> <i title="展開左側欄" class="iconfont"></i> </div> <ul class="layui-nav left fast-add" lay-filter=""> <li class="layui-nav-item"> <a href="javascript:;">+新增</a> <dl class="layui-nav-child"> <!-- 二級菜單 --> <dd><a onclick="x_admin_show('資訊','http://www.baidu.com')"><i class="iconfont"></i>資訊</a></dd> <dd><a onclick="x_admin_show('圖片','http://www.baidu.com')"><i class="iconfont"></i>圖片</a></dd> <dd><a onclick="x_admin_show('用戶','http://www.baidu.com')"><i class="iconfont"></i>用戶</a></dd> </dl> </li> </ul> <ul class="layui-nav right" lay-filter=""> <li class="layui-nav-item"> <a href="javascript:;">admin</a> <dl class="layui-nav-child"> <!-- 二級菜單 --> <dd><a onclick="x_admin_show('我的信息','http://www.baidu.com')">我的信息</a></dd> <dd><a onclick="x_admin_show('切換賬號','http://www.baidu.com')">切換賬號</a></dd> <dd><a href="./login.html">退出</a></dd> </dl> </li> <li class="layui-nav-item to-index"><a href="/">前臺首頁</a></li> </ul> </div> <!-- 頂部結束 --> <!-- 中部開始 --> <!-- 左側菜單開始 --> <div class="left-nav"> <div id="side-nav"> <ul id="nav"> <li> <a href="javascript:;"> <i class="iconfont"></i> <cite>用戶管理</cite> <i class="iconfont nav_right"></i> </a> <ul class="sub-menu"> <li> <a _href="member-list.html"> <i class="iconfont"></i> <cite>用戶列表</cite> </a> </li > <li> <a _href="member-del.html"> <i class="iconfont"></i> <cite>用戶刪除</cite> </a> </li> </ul> </li> <li> <a href="javascript:;"> <i class="iconfont"></i> <cite>帖子管理</cite> <i class="iconfont nav_right"></i> </a> <ul class="sub-menu"> <li> <a href="javascript:;"> <i class="iconfont"></i> <cite>帖子列表</cite> <i class="iconfont nav_right"></i> </a> <ul class="sub-menu"> <li> <a _href="xxx.html"> <i class="iconfont"></i> <cite>已完結</cite> </a> </li > <li> <a _href="xx.html"> <i class="iconfont"></i> <cite>未完結</cite> </a> </li> </ul> </li> <li> <a _href="member-list.html"> <i class="iconfont"></i> <cite>帖子刪除</cite> </a> </li > </ul> </li> <li> <a href="javascript:;"> <i class="iconfont"></i> <cite>系通通計</cite> <i class="iconfont nav_right"></i> </a> <ul class="sub-menu"> <li> <a _href="echarts1.html"> <i class="iconfont"></i> <cite>拆線圖</cite> </a> </li > <li> <a _href="echarts2.html"> <i class="iconfont"></i> <cite>柱狀圖</cite> </a> </li> <li> <a _href="echarts3.html"> <i class="iconfont"></i> <cite>地圖</cite> </a> </li> <li> <a _href="echarts4.html"> <i class="iconfont"></i> <cite>餅圖</cite> </a> </li> <li> <a _href="echarts5.html"> <i class="iconfont"></i> <cite>雷達圖</cite> </a> </li> <li> <a _href="echarts6.html"> <i class="iconfont"></i> <cite>k線圖</cite> </a> </li> <li> <a _href="echarts7.html"> <i class="iconfont"></i> <cite>熱力圖</cite> </a> </li> <li> <a _href="echarts8.html"> <i class="iconfont"></i> <cite>儀表圖</cite> </a> </li> </ul> </li> <li> <a href="javascript:;"> <i class="iconfont"></i> <cite>圖標字體</cite> <i class="iconfont nav_right"></i> </a> <ul class="sub-menu"> <li> <a _href="unicode.html"> <i class="iconfont"></i> <cite>圖標對應字體</cite> </a> </li> </ul> </li> </ul> </div> </div> <!-- <div class="x-slide_left"></div> --> <!-- 左側菜單結束 --> <!-- 右側主體開始 --> <div class="page-content"> <div class="layui-tab tab" lay-filter="xbs_tab" lay-allowclose="false"> <ul class="layui-tab-title"> <li class="home"><i class="layui-icon"></i>個人桌面</li> </ul> <div class="layui-tab-content"> <div class="layui-tab-item layui-show"> <iframe src='./welcome.html' frameborder="0" scrolling="yes" class="x-iframe"></iframe> </div> </div> </div> </div> <div class="page-content-bg"></div> <!-- 右側主體結束 --> <!-- 中部結束 --> <!-- 底部開始 --> <div class="footer"> <div class="copyright">Copyright ©2019 QZSSY All Rights Reserved</div> </div> <!-- 底部結束 --> <script> //百度統計可去掉 var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>
在src中建立struts.xml,並將其約束的頭導入sql
導入的約束的頭:chrome
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd">
在struts.xml進行:
一、動態方法的調用
二、 讓spring來建立Action
三、容許全部方法
整合的struts:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <!-- 動態方法的調用 --> <constant name="struts.devMode" value="true"></constant> <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant> <!-- 讓spring來建立Action --> <constant name="struts.objectFactory" value="spring"></constant> <package name="QSSY_Back" namespace="/" extends="struts-default"> <!-- 容許全部方法 --> <global-allowed-methods>regex:.*</global-allowed-methods> </package> </struts>
在web.xml中讓struts啓動
<!-- 讓struts啓動 --> <filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
在src中新建applicationContext.xml
導入約束;
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> </beans>
在applicationContext.xml進行
一、dataSource的配置
二、配置sessionFactory
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="jdbcUrl" value="jdbc:mysql:///ssh_forum"></property> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="user" value="root"></property> <property name="password" value="root"></property> </bean> <!-- 配置sessionFactory --> <bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop><!-- 自動建立表 --> <prop key="hibernate.show_sql">true</prop><!-- 打印出sql語句 --> <prop key="hibernate.format_sql">true</prop><!-- 格式化sql語句 --> </props> </property> <property name="mappingDirectoryLocations" value="classpath:com/guiyan/domain"></property> </bean>
在applicationContext.xml加入:
<!-- 配置事務 --> <bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 通知 --> <tx:advice id="advice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" /> </tx:attributes> </tx:advice> <!-- 織入 --> <aop:config> <aop:pointcut expression="execution(* com.guiyan.service.*.*(..))" id="pc"/> <aop:advisor advice-ref="advice" pointcut-ref="pc"/> </aop:config>
在web.xml加入:
<!-- 讓spring啓動 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 擴大到頁面的加載 -->
<filter>
<filter-name>openSession</filter-name>
<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSession</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
這樣三大框架的整合就完成了
最終總的代碼:
struts.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE struts PUBLIC 3 "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" 4 "http://struts.apache.org/dtds/struts-2.5.dtd"> 5 6 7 <struts> 8 9 <!-- 動態方法的調用 --> 10 <constant name="struts.devMode" value="true"></constant> 11 <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant> 12 13 14 <!-- 讓spring來建立Action --> 15 <constant name="struts.objectFactory" value="spring"></constant> 16 17 <package name="QSSY_Back" namespace="/" extends="struts-default"> 18 19 20 <!-- 容許全部方法 --> 21 <global-allowed-methods>regex:.*</global-allowed-methods> 22 23 24 </package> 25 26 27 28 29 </struts>
applicationContext.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <beans xmlns="http://www.springframework.org/schema/beans" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xmlns:aop="http://www.springframework.org/schema/aop" 7 xmlns:tx="http://www.springframework.org/schema/tx" 8 xsi:schemaLocation="http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context.xsd 12 http://www.springframework.org/schema/aop 13 http://www.springframework.org/schema/aop/spring-aop.xsd 14 http://www.springframework.org/schema/tx 15 http://www.springframework.org/schema/tx/spring-tx.xsd"> 16 17 18 19 20 <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 21 <property name="jdbcUrl" value="jdbc:mysql:///ssh_forum"></property> 22 <property name="driverClass" value="com.mysql.jdbc.Driver"></property> 23 <property name="user" value="root"></property> 24 <property name="password" value="root"></property> 25 </bean> 26 27 <!-- 配置sessionFactory --> 28 <bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> 29 <property name="dataSource" ref="dataSource"></property> 30 <property name="hibernateProperties"> 31 <props> 32 <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> 33 <prop key="hibernate.hbm2ddl.auto">update</prop><!-- 自動建立表 --> 34 <prop key="hibernate.show_sql">true</prop><!-- 打印出sql語句 --> 35 <prop key="hibernate.format_sql">true</prop><!-- 格式化sql語句 --> 36 </props> 37 </property> 38 <property name="mappingDirectoryLocations" value="classpath:com/guiyan/domain"></property> 39 </bean> 40 41 42 43 <!-- 配置事務 --> 44 <bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> 45 <property name="sessionFactory" ref="sessionFactory"></property> 46 </bean> 47 48 <!-- 通知 --> 49 <tx:advice id="advice" transaction-manager="transactionManager"> 50 <tx:attributes> 51 <tx:method name="*" /> 52 </tx:attributes> 53 </tx:advice> 54 55 <!-- 織入 --> 56 <aop:config> 57 <aop:pointcut expression="execution(* com.guiyan.service.*.*(..))" id="pc"/> 58 <aop:advisor advice-ref="advice" pointcut-ref="pc"/> 59 </aop:config> 60 61 62 63 64 65 </beans>
web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 3 <display-name>QSSY_Back</display-name> 4 <welcome-file-list> 5 <welcome-file>index.html</welcome-file> 6 <welcome-file>index.htm</welcome-file> 7 <welcome-file>index.jsp</welcome-file> 8 <welcome-file>default.html</welcome-file> 9 <welcome-file>default.htm</welcome-file> 10 <welcome-file>default.jsp</welcome-file> 11 </welcome-file-list> 12 13 14 <!-- 讓spring啓動 --> 15 <listener> 16 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 17 </listener> 18 19 <context-param> 20 <param-name>contextConfigLocation</param-name> 21 <param-value>classpath:applicationContext.xml</param-value> 22 </context-param> 23 24 <!-- 擴大到頁面的加載 --> 25 <filter> 26 <filter-name>openSession</filter-name> 27 <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> 28 </filter> 29 30 <filter-mapping> 31 <filter-name>openSession</filter-name> 32 <url-pattern>/*</url-pattern> 33 </filter-mapping> 34 35 36 <!-- 讓struts啓動 --> 37 <filter> 38 <filter-name>struts</filter-name> 39 <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> 40 </filter> 41 <filter-mapping> 42 <filter-name>struts</filter-name> 43 <url-pattern>/*</url-pattern> 44 </filter-mapping> 45 46 47 </web-app>