SSM框架(相关坐标的引入和配置文件的配置)

SSM框架

一,spring

1.spring开发的基本包坐标

在pom.xml中配置(要使用spring框架就需引入)

<dependencies>
	 <dependency> 
		 <groupId>org.springframework</groupId> 
		 <artifactId>spring-context</artifactId> 
		 <version>5.0.5.RELEASE</version> 							   
	 </dependency>
</dependencies>

2.spring配置数据源(目的为了连接数据库)

1.在pom.xml中(引入和数据库相关的坐标)

<!-- mysql驱动 -->
<dependency>
    <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <version>5.1.39</version>
</dependency>

<!--jdbc-->
<dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-jdbc</artifactId>
     <version>5.0.5.RELEASE</version>
 </dependency>
 
 <!--Druid连接池-->
 <dependency>
       <groupId>com.alibaba</groupId>
       <artifactId>druid</artifactId>
       <version>1.1.10</version>
   </dependency>
   或
   <!-- C3P0连接池 --> 
 <dependency>
	   <groupId>c3p0</groupId> 
	   <artifactId>c3p0</artifactId>
	   <version>0.9.1.2</version>
  </dependency>

2.jdbc.properties配置文件

jdbc.driver=com.mysql.jdbc.Driver  			 		<!--mysql驱动-->
jdbc.url=jdbc:mysql://localhost:3306/test  	 <!--mysql连接的数据库名-->
jdbc.username=root                                   <!--用户名-->
jdbc.password=root                                    <!--密码-->

3.在applicationContext中
引入context命名空间和约束路径:(目的是为了扫描组件和加载配置文件)

<?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: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
                            http://www.springframework.org/schema/context/spring-context.xsd">


<!--注解的组件扫描--> 
<context:component-scan base-package="域名.包名"></context:component-scan>

 <!--加载jdbc配置文件-->
<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>


<!--spring配置JdbcTemplate-->

<!--创建连接池对象   druid-->
  <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
      <property name="driverClassName" value="${jdbc.driver}"></property>
      <property name="url" value="${jdbc.url}"></property>
      <property name="username" value="${jdbc.username}"></property>
      <property name="password" value="${jdbc.password}"></property>
  </bean>
  
	或
	
<!--创建连接池对象   C3P0-->
<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}"/>
</bean>

 <!--创建JdbcTemplate对象-->
 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
     <property name="dataSource" ref="dataSource"></property>
 </bean>

3.spring集成Junit(让SpringJunit负责创建Spring容器,方便测试)

在pom.xml中配置

<!--此处需要注意的是,spring5 及以上版本要求 junit 的版本必须是 4.12 及以上--> 
<dependency> 
	<groupId>org.springframework</groupId>
	 <artifactId>spring-test</artifactId>
	 <version>5.0.5.RELEASE</version>
</dependency>
 
 <dependency>
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId>
    <version>4.12</version> 
    <scope>test</scope> 
 </dependency>

4.spring的AOP的开发

1.在pom.xml中导入坐标

<!--导入spring的context坐标,context依赖aop-->
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>5.0.5.RELEASE</version>
</dependency>

<!-- aspectj的织入 -->
<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjweaver</artifactId>
  <version>1.8.13</version>
</dependency>

2.在applicationContext.xml 配置文件中导入aop命名空间

<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"
       xsi:schemaLocation="
        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/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

<!--组件扫描-->
<context:component-scan base-package="域名.包名"/>

<!--aop的自动代理   目的是为了让spring容器能够识别注解 @Aspect等-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>

5.声明式事务控制

1.在pom.xml中引入事务的相关坐标

<dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-tx</artifactId>
     <version>5.0.5.RELEASE</version>
</dependency>

2.在applicationContext.xml 配置文件中
1)导入事务命名空间

<?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: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/tx
                            http://www.springframework.org/schema/tx/spring-tx.xsd
                            http://www.springframework.org/schema/aop
                            http://www.springframework.org/schema/aop/spring-aop.xsd">

2)创建平台事务管理器

<!--创建平台事务管理器   内部需要引用数据源,为了获取连接-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"></property>
</bean>

3)使用注解配置声明式事务控制

<!--组件扫描-->
<context:component-scan base-package="域名.包名"/>

<!--开启事务的注解驱动   用来识别@Transactional -->
<tx:annotation-driven/>

6.spring集成web环境

1.在pom.xml中

<dependency> 
	<groupId>org.springframework</groupId> 
	<artifactId>spring-web</artifactId> 
	<version>5.0.5.RELEASE</version>
 </dependency>

2.在web.xml(先加载web.xml成功后,启动服务器)中

<!--全局参数   加载spring的配置文件applicationContext.xml--> 
<context-param> 
	<param-name>contextConfigLocation</param-name> 
	<param-value>classpath:applicationContext.xml</param-value> 
</context-param> 


<!--Spring的监听器  *** 监听Web应用的启动,在Web应用启动时,该监听器内部加载Spring的配置文件,创建应用上下文对象ApplicationContext,
在将其存储到最大的域servletContext域中,通过WebApplicationContextUtils.getWebApplicationContext(servletContext)获得应用上下文对象。 -->

<listener> 
	 <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> 
</listener>

二,springMVC

1.在pom.xml中

<!--Spring坐标-->
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-context</artifactId>
	<version>5.0.5.RELEASE</version>
</dependency>
     
<!--SpringMVC坐标-->
<dependency> 
	<groupId>org.springframework</groupId>
	<artifactId>spring-webmvc</artifactId>
	<version>5.0.5.RELEASE</version> 
</dependency>

<!--Servlet坐标--> 
<dependency>
         <groupId>javax.servlet</groupId>
         <artifactId>servlet-api</artifactId>
         <version>2.5</version>
         <scope>provided</scope>
</dependency>

<!--Jsp坐标--> 
 <dependency>
         <groupId>javax.servlet.jsp</groupId>
          <artifactId>javax.servlet.jsp-api</artifactId>
          <version>2.2.1</version>
          <scope>provided</scope>
</dependency>

<!--Jackson坐标  json数据格式的工具-->
<dependency>
	<groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.9.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.9.0</version>
</dependency>

2.在spring-mvc.xml中配置(引入mvc命名空间)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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
"> 


<!--配置注解扫描    主要扫描controller层--> 
<context:component-scan base-package="域名.包名.controller"/> </beans>

<!--配置内部资源视图解析器--> 
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
	<property name="prefix" value="/jsp/"></property> 
	<property name="suffix" value=".jsp"></property> 
</bean>

<!-- 通过SpringMVC对 对象或集合进行json字符串的转换 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> 
	<property name="messageConverters"> 
		<list>
			<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/> 
		</list> 
	</property>
 </bean>
	或
<!--默认底层就会集成jackson进行对象或集合的json格式字符串的转换-->
<mvc:annotation-driven/>   <!--配合@ResponseBody一起使用,不跳转页面-->


<!--如果是日期类型的请求,存在日期格式问题-->
 	<!--声明转换器-->
    <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
        <property name="converters">
            <list>  
                <bean class="自己配置的类,实现了converter<S,T>接口"></bean>
            </list>
        </property>
    </bean>
    和
    <mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>



<!--在spring-mvc.xml配置文件中指定放行的资源     静态资源访问的开启-->
<mvc:default-servlet-handler/>
	或
<!--一个标签配置一个路径 ,如果有多个路径需要开发,则需要配置多个 mapping:表示url地址, /** 表示所有路径 location:磁盘上的文件资源 --> 
<mvc:resources mapping="/js/**" location="/js/"/>


<!--在直接响应字符串数据时,中文数据会乱码 。配置全局字符集,对所有的方法都有效    例如:return "啦啦";-->
<!-- 开启SpringMVC注解支持 -->
<mvc:annotation-driven>
	<mvc:message-converters>
		<bean class="org.springframework.http.converter.StringHttpMessageConverter"> 
			<property name="defaultCharset" value="UTF-8" />
		</bean>
	</mvc:message-converters> 
</mvc:annotation-driven>

3.在web.xml中

<!--配置SpringMVC的核心控制器(也称前端控制器)-->
<servlet>
	<servlet-name>DispatcherServlet</servlet-name>
	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
	<init-param> 
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring-mvc.xml</param-value>
	</init-param>
	<load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
	<servlet-name>DispatcherServlet</servlet-name>
	<url-pattern>/</url-pattern> 
</servlet-mapping>


<!--配置全局过滤的filter   用来解决post请求的中文乱码问题--> 
<filter>
	<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name> 
	 <url-pattern>/*</url-pattern> 
 </filter-mapping>

springMVC中的文件上传

1.在pom.xml中

<dependency>
	<groupId>commons-fileupload</groupId>
	<artifactId>commons-fileupload</artifactId>
	<version>1.3.1</version>
</dependency>

<dependency>
	<groupId>commons-io</groupId>
	<artifactId>commons-io</artifactId>
	<version>2.4</version>
</dependency>

2.在spring-mvc.xml配置文件中(配置文件解析器)

<!--注意:  bean的id必须为"multipartResolver"-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
     <property name="defaultEncoding" value="UTF-8"></property>
     <property name="maxUploadSize" value="500000"></property>
</bean>

三,Mybatis

1.基本配置

1.在pom.xml中导入坐标

<dependencies>
	<!--因为mybatis是持久层框架,操作数据库,所以需引入mysql驱动-->
   <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.26</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.4.6</version>
    </dependency>
    <!--引入junit方便测试-->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>

2.在sqlMapConfig核心配置文件中

<!--引入约束-->
<?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>
    <!--加载jdbc的外部资源-->
    <properties resource="jdbc.properties"></properties>
    <!--配置数据源-->
    <environments default="mysql">
        <environment id="mysql">
            <transactionManager type="JDBC"></transactionManager>
            <dataSource type="POOLED">
                <property name="driver" value="${jdbc.driver}"/>
                <property name="url" value="${jdbc.url}"/>
                <property name="username" value="${jdbc.username}"/>
                <property name="password" value="${jdbc.password}"/>
            </dataSource>
        </environment>
    </environments>
</configuration>

3.在xxxMapper.xml映射文件中

<!--引入映射文件的约束-->
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

2.分页插件

1.在pom.xml中

<dependency>
   	<groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.1.10</version>
</dependency>

2.在sqlMapConfig.xml核心配置文件中

<!--配置分页的插件-->
<plugins>
    <plugin interceptor="com.github.pagehelper.PageInterceptor">
        <property name="helperDialect" value="mysql"/>
        <property name="reasonable" value="true"/>
    </plugin>
</plugins>

3.在测试中

/*在查询之前先设置分页参数*/
PageHelper.startPage(当前页,每页显示的条数);

四,SSM框架的整合

1.pom.xml文件(导入坐标)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.itcast</groupId>
    <artifactId>ssm_demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>

        <!--mybatis框架-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.8.0-beta4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <!--spring框架-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.0.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.0.5.RELEASE</version>
        </dependency>

        <!--spring集成junit测试-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.0.5.RELEASE</version>
        </dependency>

        <!--springMVC框架-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.0.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.2.1</version>
            <scope>provided</scope>
        </dependency>

        <!--连接池-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.9</version>
        </dependency>

        <!--mybatis整合spring-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!--json数据格式 依赖了其他两个-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.0</version>
        </dependency>

        <!--分页插件-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.10</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <!--tomcat插件-->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <!-- tomcat7的插件, 不同tomcat版本这个也不一样 -->
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <!-- 通过maven tomcat7:run运行项目时,访问项目的端口号 -->
                    <port>80</port>
                    <!-- 项目访问路径 -->
                    <path>/</path>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2.applicationContext.xml(spring的配置文件)

<?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: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 http://www.springframework.org/schema/context/spring-context.xsd">

    <!--配置组件扫描  可以只扫描service-->
    <context:component-scan base-package="cn.br.service"></context:component-scan>

    <!--mybatis和spring的整合-->
    <!--加载jdbc配置文件-->
     <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>

     <!--创建连接池对象-->
     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
         <property name="driverClassName" value="${jdbc.driver}"></property>
         <property name="url" value="${jdbc.url}"></property>
         <property name="username" value="${jdbc.username}"></property>
         <property name="password" value="${jdbc.password}"></property>
     </bean>

    <!--创建SqlSessionFactory工厂对象-->
    <!--配置分页助手-->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="typeAliasesPackage" value="cn.br.pojo"></property>
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>
                            helperDialect=mysql
                            reasonable=true
                        </value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>

    <!--创建mapper接口的实现类(代理)对象,并存放在bean容器中
        通过扫描包下的接口找到resources下的和接口在相同目录下的映射文件
    -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.br.mapper"></property>
    </bean>
</beans>

3.spring-mvc.xml(springMVC的配置文件)

<?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: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">

    <!--配置组件扫描  只扫描controller-->
    <context:component-scan base-package="cn.br.controller"></context:component-scan>

    <!--配置内部资源视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

    <!--配置注解驱动    底层会转换为json格式的字符串-->
    <mvc:annotation-driven></mvc:annotation-driven>

    <!--放行静态资源-->
    <mvc:default-servlet-handler></mvc:default-servlet-handler>
</beans>

4.log4j.properties(日志文件)

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:/mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=debug, stdout

5.jdbc.properties(配置数据库的信息)

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm
jdbc.username=root
jdbc.password=root

6.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
		  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
           version="3.0">
    <!--配置前端控制器-->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!--配置监听器,监听web应用的启动-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!--配置全局参数,加载spring的配置文件-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!--配置过滤器解决post请求的中文乱码问题-->
    <filter>
        <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

五,SSM框架整合的项目结构图

在这里插入图片描述
在这里插入图片描述

其他:pom.xml文件中jdk和tomcat插件

<build>
    <plugins>
    
          <!--jdk编译插件-->
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>1.8</source>
                  <target>1.8</target>
                  <encoding>utf-8</encoding>
              </configuration>
          </plugin>
          
         <!--tomcat插件-->
         <plugin>
             <groupId>org.apache.tomcat.maven</groupId>
             <!-- tomcat7的插件, 不同tomcat版本这个也不一样 -->
             <artifactId>tomcat7-maven-plugin</artifactId>
             <version>2.2</version>
             <configuration>
                 <!-- 通过maven tomcat7:run运行项目时,访问项目的端口号 -->
                 <port>8080</port>
                 <!-- 项目访问路径 -->
                 <path>/</path>
             </configuration>
         </plugin>
     </plugins>
  </build>

未完待续…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值