SSM管理系統設計所需配置文件

基礎Jar包準備

1.Sping框架所需的Jar包
http://repo.spring.io/simple/libs-release-local/org/springframework/spring/
2.MyBatis框架所需的Jar包
https://github.com/mybatis/mybatis-3/releases
3.commons logging包
http://commons.apache.org/proper/commons-logging/download_logging.cgi
4.MyBatis與Spring整合的中間Jar包
https://mvnrepository.com/artifact/org.mybatis/mybatis-spring
5.MySQL數據庫驅動所需Jar包
https://dev.mysql.com/downloads/connector/j/5.1.html
6.DBCP連接池Jar包
http://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi
7.JSTL包
http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/

SSM框架整合

(1)安裝Tomcat和MySQL,並確保其可正常工作。
(2)在Eclipse中新建Web項目,加入Tomcat Web服務環境。
(3)將所需Jar包複製到/WEB-INF/lib文件夾中。
(4)在/WEB-INF文件夾中,新建web.xml文件,內容如下:

<?xml version="1.0" encoding="UTF-8"?>
<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">
  	<!-- 配置加載Spring文件的監聽器-->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>
	<listener>
		<listener-class>
		     org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	<!-- 編碼過濾器 -->
	<filter>
		<filter-name>encoding</filter-name>
		<filter-class>
		     org.springframework.web.filter.CharacterEncodingFilter
		</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encoding</filter-name>
		<url-pattern>*.action</url-pattern>
	</filter-mapping>
	<!-- 配置Spring MVC前端核心控制器 -->
	<servlet>
		<servlet-name>springmvc</servlet-name>
		<servlet-class>
		     org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:springmvc-config.xml</param-value>
		</init-param>
		<!-- 配置服務器啓動後立即加載Spring MVC配置文件 -->
    	<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>springmvc</servlet-name>
		<!--/:攔截所有請求(除了jsp)-->
		<url-pattern>/</url-pattern>
	</servlet-mapping>
</web-app>

(5)在src目錄下,分別創建數據庫常量配置文件db.properties、Spring配置文件applicationContext.xml、springmvc-config.xml和MyBatis配置文件mybatis-config.xml。三個文件的內容如下:

db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/bbs?characterEncoding=GBK//數據庫自己改一下
jdbc.username=root
jdbc.password=root
jdbc.maxTotal=30
jdbc.maxIdle=10
jdbc.initialSize=5

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.3.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
    <!-- 讀取db.properties -->
    <context:property-placeholder location="classpath:db.properties"/>
    <!-- 配置數據源 -->
	<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
		<!--數據庫驅動 -->
		<property name="driverClassName" value="${jdbc.driver}" />
		<!--連接數據庫的url -->
		<property name="url" value="${jdbc.url}" />
		<!--連接數據庫的用戶名 -->
		<property name="username" value="${jdbc.username}" />
		<!--連接數據庫的密碼 -->
		<property name="password" value="${jdbc.password}" />
		<!--最大連接數 -->
		<property name="maxTotal" value="${jdbc.maxTotal}" />
		<!--最大空閒連接  -->
		<property name="maxIdle" value="${jdbc.maxIdle}" />
		<!--初始化連接數  -->
		<property name="initialSize" value="${jdbc.initialSize}" />
	</bean>
     <!-- 事務管理器,依賴於數據源 -->
	<bean id="transactionManager" class=
     "org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>	
    <!-- 開啓事務註解 -->
	<tx:annotation-driven transaction-manager="transactionManager"/>
    <!-- 配置MyBatis工廠SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
         <!--注入數據源 -->
         <property name="dataSource" ref="dataSource" />
         <!--指定核MyBatis心配置文件位置 -->
  <property name="configLocation" value="classpath:mybatis-config.xml" />
    </bean>
    <!-- 配置mapper掃描器 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.dao"/>
	</bean>
    <!-- 掃描Service --> 
    <context:component-scan base-package="com.service" />
</beans>

springmvc-config.xml

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
  http://www.springframework.org/schema/mvc 
  http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 
  http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context-4.3.xsd">
	<!-- 配置包掃描器,掃描@Controller註解的類 -->
	<context:component-scan base-package="com.controller" />
	<!-- 加載註解驅動 -->
	<mvc:annotation-driven />
	<!-- 配置視圖解析器 -->
	<bean class=
    "org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
</beans>

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<!-- 別名定義 -->
	<typeAliases>
		<package name="com.po" />
	</typeAliases>
</configuration>

前端框架

  1. LayUi框架
    https://www.layui.com/doc/
    在這裏插入圖片描述
  2. BookStrap框架
    https://v3.bootcss.com/
    在這裏插入圖片描述

我是自己趕作業才用框架,不然H5也是可以的

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章