<!doctype html>SSM框架搭建css
x
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<!-- 日誌文件-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<!-- spring-->
<!-- 包含spring框架的核心工具類-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 這個jar包是全部應用都能用到的,包括bean的建立和管理,以及IOC和DI功能(反轉控制和依賴注入)-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 能夠使用應用上下文獲取全部的bean-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 包括jdbc數據訪問的全部類-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring框架裏的事務管理類-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- web開發須要的類-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring mvc框架的類-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<!-- servlet web-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<!-- json解析-->
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9.3</version>
</dependency>
<!-- Map工具類,對java collection的擴展-->
<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<!-- Dao:mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.2</version>
</dependency>
<!-- spring整合mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- 鏈接mysql包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
<!-- 數據庫鏈接池-->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
dao層:持久層html
service層:事務層java
web層:controller(控制)層node
xxxxxxxxxx
<configuration>
<!-- 全局配置-->
<settings>
<setting name="useGeneratedKeys" value="true"/>
<!-- 使用列標籤代替列名 默認true-->
<setting name="useColumnLabel" value="true"/>
<!-- 開啓駝峯命名轉換table{create_time}-entity{createTime}-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
service層的配置:spring-service.xmlmysql
web層的配置:spring-web.xmlweb
dao層:spring
1,配置數據庫的屬性配置sql
2,配置數據庫鏈接池數據庫
3,配置sqlSessionFactoryBeanjson
4,配置MapperScannerConfigurer,掃描dao層的接口,自動實現動態代理,注入到spring容器中
xxxxxxxxxx
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- 配置整合mybatis的過程-->
<!-- 1,配置數據庫的屬性配置 :${url}-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2,數據庫鏈接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 配置鏈接池屬性-->
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- c3p0鏈接池的屬性-->
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<!-- 關閉鏈接後不自動commint-->
<property name="autoCommitOnClose" value="false"/>
<!-- 獲取鏈接超時時間-->
<property name="checkoutTimeout" value="10000"/>
<!-- 獲取鏈接失敗重試次數-->
<property name="acquireRetryAttempts" value="2"/>
</bean>
<!-- 3,sqlsessionfactoryBean-->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="com.imooc.o2o.entity"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<property name="mapperLocations" value="classpath:mapping/*.xml"/>
</bean>
<!-- 4,掃描dao層包裏的接口,實現動態代理,注入到spring容器中-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean"/>
<property name="basePackage" value="com.imooc.o2o.dao"/>
</bean>
</beans>
service層:
1,掃描service層下使用註解的全部類型
2,配置jdbc事務管理器
3,配置基於註解的聲明式事務管理
xxxxxxxxxx
<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">
<import resource="spring-dao.xml"/>
<!-- 掃描service包下使用註解的全部類型-->
<context:component-scan base-package="com.imooc.o2o.service"/>
<!-- 配置事物管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 數據庫鏈接池-->
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置基於註解的聲明式事務-->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
web層:
spring-mvc層
1,開啓spring-mvc註解模式
2,靜態資源默認servlet配置
3,配置視圖解析器
4,掃描web層下全部的bean
xxxxxxxxxx
<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:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 配置spring mvc-->
<!-- 1,開啓spring mvc 註解方式-->
<mvc:annotation-driven/>
<!-- 2,靜態資源默認servlet配置
1,加入對靜態資源的處理,js,css,png
2,容許使用/作總體映射
-->
<mvc:resources mapping="/resources/**" location="/resources/"/>
<mvc:default-servlet-handler/>
<!--3,視圖解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/html/"/>
<property name="suffix" value=".html"/>
</bean>
<!-- 4,掃描web相關的bean-->
<context:component-scan base-package="com.imooc.o2o.web"/>
</beans>