springmvc整合ssm配置


导入依赖

<?xml version="1.0" encoding="UTF-8"?>
"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">
    4.0.0

    com.kuang
    ssmbuild
    1.0-SNAPSHOT


    
        
        
            junit
            junit
            4.12
        
        
        
            mysql
            mysql-connector-java
            5.1.47
        
        
        
            com.mchange
            c3p0
            0.9.5.2
        

        
        
            javax.servlet
            servlet-api
            2.5
        
        
            javax.servlet.jsp
            jsp-api
            2.2
        
        
            javax.servlet
            jstl
            1.2
        

        
        
            org.mybatis
            mybatis
            3.5.2
        
        
            org.mybatis
            mybatis-spring
            2.0.2
        

        
        
            org.springframework
            spring-webmvc
            5.1.9.RELEASE
        
        
            org.springframework
            spring-jdbc
            5.1.9.RELEASE
        



        
            org.projectlombok
            lombok
            1.16.12
            provided
        
        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.9.8
        

    



    
        
            
                src/main/java
                
                    **/*.properties
                    **/*.xml
                
                false
            
            
                src/main/resources
                
                    **/*.properties
                    **/*.xml
                
                false
            
        
    


applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
"http://www.springframework.org/schema/beans"
       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">
    "classpath:spring-service.xml">
    "classpath:spring-dao.xml">
    "classpath:spring-mvc.xml">
spring-service.xml
<?xml version="1.0" encoding="UTF-8"?>
"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"> base-package="com.kuang.service"/> "BookServiceImpl" class="com.kuang.service.BookServiceImpl"> "bookMapper" ref="bookMapper"> "transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> "dataSource" ref="dataSource">

spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
"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
       https://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       https://www.springframework.org/schema/mvc/spring-mvc.xsd">

    
    base-package="com.kuang.controller"/>


    
    
   "true"> class="org.springframework.http.converter.StringHttpMessageConverter"> "UTF-8"/> class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> "objectMapper"> class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"> "failOnEmptyBeans" value="false"/>
class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver"> "prefix" value="/WEB-INF/jsp/" /> "suffix" value=".jsp" />
spring-dao.xml
<?xml version="1.0" encoding="UTF-8"?>
"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">


   "classpath:database.properties">



    "dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        "driverClass" value="${jdbc.driver}">
        "jdbcUrl" value="${jdbc.url}">
        "user" value="${jdbc.username}">
        "password" value="${jdbc.password}">

        
        "maxPoolSize" value="30"/>
        "minPoolSize" value="10"/>
        
        "autoCommitOnClose" value="false"/>
        
        "checkoutTimeout" value="10000"/>
        
        "acquireRetryAttempts" value="2"/>

    




    "sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        "dataSource" ref="dataSource">

        "configLocation" value="classpath:mybatis-config.xml">

    


    class="org.mybatis.spring.mapper.MapperScannerConfigurer">

        "sqlSessionFactoryBeanName" value="sqlSessionFactory">

        "basePackage" value="com.kuang.dao">
    

mybatis-comfig.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">


    
        "logImpl" value="STDOUT_LOGGING"/>
    

    
        "com.kuang.pojo"/>
    
    
    
        class="com.kuang.dao.BookMapper">
    

database.propertes

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=root