SSM整合

本文详细介绍了一个基于MyBatis和Spring的项目搭建过程,包括导入所有必要的jar包、配置文件详解等内容。涵盖数据库连接、ORM框架配置、日志记录等关键技术点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、导入所需的所有jar包

pom.xml

<dependencies>


      <!--**********************工具包[日志、junit4、依赖包]**********************-->
      <!--Java依赖包-->
      <dependency>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
          <version>1.2</version>
      </dependency>

      <!--日志-->
      <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.17</version>
      </dependency>

      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.7.5</version>
      </dependency>

      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
          <version>1.7.5</version>
          <scope>test</scope>
      </dependency>

      <!--junit-->
      <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.12</version>
          <scope>test</scope>
      </dependency>


      <!--**********************数据库[数据库连接池+数据库连接]**********************-->
      <!--德鲁伊数据库连接池-->
      <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>druid</artifactId>
          <version>1.0.12</version>
      </dependency>

      <!--数据库连接池-->
      <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>5.1.26</version>
      </dependency>


      <!--**********************MyBatis**********************-->
      <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
          <version>3.3.0</version>
      </dependency>

      <dependency>
          <groupId>org.mybatis.generator</groupId>
          <artifactId>mybatis-generator-core</artifactId>
          <version>1.3.2</version>
      </dependency>

      <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>1.2.2</version>
      </dependency>

    <!--分页包-->
    <!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper</artifactId>
        <version>4.0.0</version>
    </dependency>


    <!--**********************Spring**********************-->
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aop</artifactId>
          <version>4.2.4.RELEASE</version>
      </dependency>

      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
          <version>4.2.4.RELEASE</version>
      </dependency>

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

      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
          <version>4.2.4.RELEASE</version>
      </dependency>

      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-expression</artifactId>
          <version>4.2.4.RELEASE</version>
      </dependency>

      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-jdbc</artifactId>
          <version>4.2.4.RELEASE</version>
      </dependency>

      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-test</artifactId>
          <version>4.2.4.RELEASE</version>
          <scope>test</scope>
      </dependency>

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


      <!--**********************Spring AOP**********************-->
      <dependency>
          <groupId>aopalliance</groupId>
          <artifactId>aopalliance</artifactId>
          <version>1.0</version>
      </dependency>

      <dependency>
          <groupId>org.ow2.asm</groupId>
          <artifactId>asm</artifactId>
          <version>4.2</version>
      </dependency>

      <dependency>
          <groupId>org.aspectj</groupId>
          <artifactId>aspectjrt</artifactId>
          <version>1.7.1</version>
      </dependency>

      <dependency>
          <groupId>org.aspectj</groupId>
          <artifactId>aspectjweaver</artifactId>
          <version>1.7.1</version>
      </dependency>

                   <!--springmvc-->

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.2.4.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.2.4.RELEASE</version>
    </dependency>

    
<!--***********jstlel表达式所需jar***********-->
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.tomcat/el-api --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>el-api</artifactId> <version>6.0.29</version> </dependency> <!-- https://mvnrepository.com/artifact/jason/jason --></dependencies>
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.2</version>
            <configuration>
                <verbose>true</verbose>
                <overwrite>true</overwrite>
            </configuration>
        </plugin>
    </plugins>
</build>

2、导入所需的资源文件


一、log4j.properties 用时直接复制,内容固定
### 设置###
log4j.rootLogger = debug,stdout,D,E

### 输出信息到控制抬 ###
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 = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n

### 输出DEBUG 级别以上的日志到=E://logs/error.log ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = E://logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

### 输出ERROR 级别以上的日志到=E://logs/error.log ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =E://logs/error.log 
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR 
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n


jdbc.properties
//与generatorconfig.xml文件中对应
jdbc.driverlocation=D:/Program Files (x86)/LocalWarehome/mysql/mysql-connector-java/5.1.26/mysql-connector-java-5.1.26.jar
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/employee
jdbc.username=root
jdbc.password=123456
springmvc-servlet.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: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-3.0.xsd
            http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">



    <!--添加springmvc扫描器 只扫描@controller-->
    <context:component-scan base-package="cn.vp.controller">
        <context:include-filter  type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>


    <!--配置视图解析器-->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver">

        <!--配置前缀-->
        <property name="prefix" value="/WEB-INF/JSP/"/>
        <!--配置后缀-->
        <property name="suffix" value=".jsp"/>
        <!--使用jstl配置-->
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    </bean>


    <!--放行-->
    <!--静态资源处理器-->
    <mvc:resources mapping="/images/**" location="/images"/>
    <mvc:resources mapping="/images/**" location="/js/"/>

</beans>
                     

mybatis-generator-config_1_0.dtd
整合mybatis与spring时所需,固定的内容,用时直接复制
<?xml version="1.0" encoding="UTF-8"?>
<!--

       Copyright 2006-2017 the original author or authors.

       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.

-->
<!--
  This DTD defines the structure of the MyBatis generator configuration file.
  Configuration files should declare the DOCTYPE as follows:
  
  <!DOCTYPE generatorConfiguration PUBLIC
    "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  
  Please see the documentation included with MyBatis generator for details on each option
  in the DTD.  You may also view documentation on-line here:
  
  http://www.mybatis.org/generator/
  
-->

<!--
  The generatorConfiguration element is the root element for configurations.
-->
<!ELEMENT generatorConfiguration (properties?, classPathEntry*, context+)>
                        
<!--
  The properties element is used to define a standard Java properties file
  that contains placeholders for use in the remainder of the configuration
  file.
-->
<!ELEMENT properties EMPTY>
<!ATTLIST properties
  resource CDATA #IMPLIED
  url CDATA #IMPLIED>
  
<!--
  The context element is used to describe a context for generating files, and the source
  tables.
-->
<!ELEMENT context (property*, plugin*, commentGenerator?, (connectionFactory | jdbcConnection), javaTypeResolver?,
                         javaModelGenerator, sqlMapGenerator?, javaClientGenerator?, table+)>
<!ATTLIST context id ID #REQUIRED
  defaultModelType CDATA #IMPLIED
  targetRuntime CDATA #IMPLIED
  introspectedColumnImpl CDATA #IMPLIED>

<!--
  The connectionFactory element is used to describe the connection factory used
  for connecting to the database for introspection.  Either connectionFacoty
  or jdbcConnection must be specified, but not both.
-->
<!ELEMENT connectionFactory (property*)>
<!ATTLIST connectionFactory
  type CDATA #IMPLIED>

<!--
  The jdbcConnection element is used to describe the JDBC connection that the generator
  will use to introspect the database.
-->
<!ELEMENT jdbcConnection (property*)>
<!ATTLIST jdbcConnection 
  driverClass CDATA #REQUIRED
  connectionURL CDATA #REQUIRED
  userId CDATA #IMPLIED
  password CDATA #IMPLIED>

<!--
  The classPathEntry element is used to add the JDBC driver to the run-time classpath.
  Repeat this element as often as needed to add elements to the classpath.
-->
<!ELEMENT classPathEntry EMPTY>
<!ATTLIST classPathEntry
  location CDATA #REQUIRED>

<!--
  The property element is used to add custom properties to many of the generator's
  configuration elements.  See each element for example properties.
  Repeat this element as often as needed to add as many properties as necessary
  to the configuration element.
-->
<!ELEMENT property EMPTY>
<!ATTLIST property
  name CDATA #REQUIRED
  value CDATA #REQUIRED>

<!--
  The plugin element is used to define a plugin.
-->
<!ELEMENT plugin (property*)>
<!ATTLIST plugin
  type CDATA #REQUIRED>

<!--
  The javaModelGenerator element is used to define properties of the Java Model Generator.
  The Java Model Generator builds primary key classes, record classes, and Query by Example 
  indicator classes.
-->
<!ELEMENT javaModelGenerator (property*)>
<!ATTLIST javaModelGenerator
  targetPackage CDATA #REQUIRED
  targetProject CDATA #REQUIRED>

<!--
  The javaTypeResolver element is used to define properties of the Java Type Resolver.
  The Java Type Resolver is used to calculate Java types from database column information.
  The default Java Type Resolver attempts to make JDBC DECIMAL and NUMERIC types easier
  to use by substituting Integral types if possible (Long, Integer, Short, etc.)
-->
<!ELEMENT javaTypeResolver (property*)>
<!ATTLIST javaTypeResolver
  type CDATA #IMPLIED>

<!--
  The sqlMapGenerator element is used to define properties of the SQL Map Generator.
  The SQL Map Generator builds an XML file for each table that conforms to iBATIS'
  SqlMap DTD.
-->
<!ELEMENT sqlMapGenerator (property*)>
<!ATTLIST sqlMapGenerator
  targetPackage CDATA #REQUIRED
  targetProject CDATA #REQUIRED>

<!--
  The javaClientGenerator element is used to define properties of the Java client Generator.
  The Java Client Generator builds Java interface and implementation classes
  (as required) for each table.
  If this element is missing, then the generator will not build Java Client classes.
-->
<!ELEMENT javaClientGenerator (property*)>
<!ATTLIST javaClientGenerator
  type CDATA #REQUIRED
  targetPackage CDATA #REQUIRED
  targetProject CDATA #REQUIRED
  implementationPackage CDATA #IMPLIED>

<!--
  The table element is used to specify a database table that will be the source information
  for a set of generated objects.
-->
<!ELEMENT table (property*, generatedKey?, domainObjectRenamingRule?, columnRenamingRule?, (columnOverride | ignoreColumn | ignoreColumnsByRegex)*) >
<!ATTLIST table
  catalog CDATA #IMPLIED
  schema CDATA #IMPLIED
  tableName CDATA #REQUIRED
  alias CDATA #IMPLIED
  domainObjectName CDATA #IMPLIED
  mapperName CDATA #IMPLIED
  sqlProviderName CDATA #IMPLIED
  enableInsert CDATA #IMPLIED
  enableSelectByPrimaryKey CDATA #IMPLIED
  enableSelectByExample CDATA #IMPLIED
  enableUpdateByPrimaryKey CDATA #IMPLIED
  enableDeleteByPrimaryKey CDATA #IMPLIED
  enableDeleteByExample CDATA #IMPLIED
  enableCountByExample CDATA #IMPLIED
  enableUpdateByExample CDATA #IMPLIED
  selectByPrimaryKeyQueryId CDATA #IMPLIED
  selectByExampleQueryId CDATA #IMPLIED
  modelType CDATA #IMPLIED
  escapeWildcards CDATA #IMPLIED
  delimitIdentifiers CDATA #IMPLIED
  delimitAllColumns CDATA #IMPLIED>

<!--
  The columnOverride element is used to change certain attributes of the column
  from their default values.
-->
<!ELEMENT columnOverride (property*)>
<!ATTLIST columnOverride
  column CDATA #REQUIRED
  property CDATA #IMPLIED
  javaType CDATA #IMPLIED
  jdbcType CDATA #IMPLIED
  typeHandler CDATA #IMPLIED
  isGeneratedAlways CDATA #IMPLIED
  delimitedColumnName CDATA #IMPLIED>

<!--
  The ignoreColumn element is used to identify a column that should be ignored.
  No generated SQL will refer to the column, and no property will be generated
  for the column in the model objects.
-->
<!ELEMENT ignoreColumn EMPTY>
<!ATTLIST ignoreColumn
  column CDATA #REQUIRED
  delimitedColumnName CDATA #IMPLIED>

<!--
  The ignoreColumnsByRegex element is used to identify a column pattern that should be ignored.
  No generated SQL will refer to the column, and no property will be generated
  for the column in the model objects.
-->
<!ELEMENT ignoreColumnsByRegex (except*)>
<!ATTLIST ignoreColumnsByRegex
  pattern CDATA #REQUIRED>

<!--
  The except element is used to identify an exception to the ignoreColumnsByRegex rule.
  If a column matches the regex rule, but also matches the exception, then the
  column will be included in the generated objects.
-->
<!ELEMENT except EMPTY>
<!ATTLIST except
  column CDATA #REQUIRED
  delimitedColumnName CDATA #IMPLIED>

<!--
  The generatedKey element is used to identify a column in the table whose value
  is calculated - either from a sequence (or some other query), or as an identity column.
-->
<!ELEMENT generatedKey EMPTY>
<!ATTLIST generatedKey
  column CDATA #REQUIRED
  sqlStatement CDATA #REQUIRED
  identity CDATA #IMPLIED
  type CDATA #IMPLIED>

<!--
  The domainObjectRenamingRule element is used to specify a rule for renaming
  object domain name before the corresponding domain object name is calculated
-->
<!ELEMENT domainObjectRenamingRule EMPTY>
<!ATTLIST domainObjectRenamingRule
  searchString CDATA #REQUIRED
  replaceString CDATA #IMPLIED>

<!--
  The columnRenamingRule element is used to specify a rule for renaming
  columns before the corresponding property name is calculated
-->
<!ELEMENT columnRenamingRule EMPTY>
<!ATTLIST columnRenamingRule
  searchString CDATA #REQUIRED
  replaceString CDATA #IMPLIED>

<!--
  The commentGenerator element is used to define properties of the Comment Generator.
  The Comment Generator adds comments to generated elements.
-->
<!ELEMENT commentGenerator (property*)>
<!ATTLIST commentGenerator
  type CDATA #IMPLIED>
  
applicationConext.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:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">
    <!--mybatis配置和spring配置整合在一起-->

    <!--引入db.properties-->
    <context:property-placeholder location="jdbc.properties"/>

    <!--开启spring ioc注解及扫描-->
    <context:annotation-config/>
    <context:component-scan base-package="cn.vp"/>

    <!--编写mybatis配置文件-->
    <!--配置连接池druid-->
    <bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="initialSize" value="5"></property>
        <property name="maxActive" value="20"></property>
        <property name="minIdle" value="2"></property>
        <property name="maxWait" value="5000"></property>

    </bean>
    <!--配置sqlsessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

        <!--配置数据源-->
        <property name="dataSource" ref="druidDataSource"/>

        <!--加载xml文件-->
        <property name="mapperLocations" value="classpath:cn/vp/dao/mapper/*.xml"/>
        <!--给类取别名mybatis-->
        <property name="typeAliasesPackage" value="cn.vp.bean"/>


        <!--配置PageHelper的参数实现分页  spring4.0以上的配置方法  spring3的配置不一样-->
        <property name="plugins">
            <array>

            </array>
        </property>


    </bean>


    <!--配置扫描器-->

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--5.1 将映射文件与接口建立关联 -->
        <property name="basePackage" value="cn.vp.dao"/>
        <!-- 5.2此处配置的是value 防止读取不到db.properties配置文件中的信息 -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <!--配置事务-->
    <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="druidDataSource"/>
    </bean>


    <!--开启事务注解-->
    <tx:annotation-driven transaction-manager="dataSourceTransactionManager"/>

</beans>


generatorconfig.xml  通过mybatis插件生成pojo及mapper
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
      PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
      "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
   <properties resource="jdbc.properties"/>
   <!-- 数据库驱动 改动1 -->
   <classPathEntry location="${jdbc.driverlocation}" />
   <context id="DB2Tables" targetRuntime="MyBatis3">
      <commentGenerator>
         <property name="suppressDate" value="true" />
         <!-- 是否去除自动生成的注释 true:是 : false:-->
         <property name="suppressAllComments" value="true" />
      </commentGenerator>
      <!--数据库链接URL,用户名、密码 -->
      <jdbcConnection driverClass="${jdbc.driver}"
         connectionURL="${jdbc.url}" userId="${jdbc.username}" password="${jdbc.password}">
      </jdbcConnection>
      <!-- 默认false,把JDBC DECIMAL  NUMERIC 类型解析为 Integer true,把JDBC DECIMAL  
         NUMERIC 类型解析为java.math.BigDecimal -->
      <javaTypeResolver>
         <property name="forceBigDecimals" value="false" />
      </javaTypeResolver>
      <!-- 生成模型的包名和位置 -->
      <javaModelGenerator targetPackage="cn.vp.bean"
         targetProject="src/main/java">
         <!-- enableSubPackages:是否让schema作为包的后缀 -->
         <property name="enableSubPackages" value="true" />
         <!-- 从数据库返回的值被清理前后的空格 -->
         <property name="trimStrings" value="true" />
      </javaModelGenerator>
      <!-- 生成映射文件的包名和位置 -->
      <sqlMapGenerator targetPackage="cn.vp.dao.mapper"
         targetProject="src/main/java">
         <property name="enableSubPackages" value="true" />
      </sqlMapGenerator>
      <!-- 生成DAO的包名和位置 -->
      <javaClientGenerator type="XMLMAPPER"
         targetPackage="cn.vp.dao" targetProject="src/main/java">
         <property name="enableSubPackages" value="true" />
      </javaClientGenerator>
      <!-- 要生成哪些表 -->
      <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
      <table tableName="emp"
             domainObjectName="emp"
            enableCountByExample="false" 
            enableUpdateByExample="false"
            enableDeleteByExample="false"
            enableSelectByExample="false"
            selectByExampleQueryId="false"></table>

      <table tableName="dept" domainObjectName="dept"
         enableCountByExample="false" enableUpdateByExample="false"
         enableDeleteByExample="false" enableSelectByExample="false"
         selectByExampleQueryId="false"></table>
   </context>
</generatorConfiguration>
springmvc-servlet.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: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-3.0.xsd
            http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">



    <!--添加springmvc扫描器 只扫描@controller-->
    <context:component-scan base-package="cn.vp.controller">
        <context:include-filter  type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>


    <!--配置视图解析器-->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver">

        <!--配置前缀-->
        <property name="prefix" value="/WEB-INF/JSP/"/>
        <!--配置后缀-->
        <property name="suffix" value=".jsp"/>
        <!--使用jstl配置-->
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    </bean>


    <!--放行-->
    <!--静态资源处理器-->
    <mvc:resources mapping="/images/**" location="/images"/>
    <mvc:resources mapping="/images/**" location="/js/"/>

</beans>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

  <!--启动spring监听器-->
  <listener>
    <listener-class>org.springframework.web.context.ContextCleanupListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationConext.xml</param-value>
  </context-param>
  
  <!--加载springmvc配置文件-->
  <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-servlet.xml</param-value>
  </init-param>
    <load-on-startup>1</load-on-startup>


  </servlet>



  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>





  <display-name>Archetype Created Web Application</display-name>
</web-app>


最后两个属于springmvc的配置




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值