spring+springmvc+mybatis(ssm)


1.jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/jkdb?characterEncoding=utf-8
jdbc.username=root
jdbc.password=123

c3p0.pool.size.max=20
c3p0.pool.size.min=5
c3p0.pool.size.ini=3
c3p0.pool.size.increment=2

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

    
    

3.bean.xml

<?xml version="1.0" encoding="UTF-8"?>
"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: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-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 
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
            
    
    base-package="cn.itcast.jk.service,cn.itcast.jk.dao"/>
    "classpath:jdbc.properties"/>
                
            
    "dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        "driverClass" value="${jdbc.driverClassName}"/>
        "jdbcUrl" value="${jdbc.url}"/>
        "user" value="${jdbc.username}"/>
        "password" value="${jdbc.password}"/>

        "maxPoolSize" value="${c3p0.pool.size.max}"/>
        "minPoolSize" value="${c3p0.pool.size.min}" />
        "initialPoolSize" value="${c3p0.pool.size.ini}"/>
        "acquireIncrement" value="${c3p0.pool.size.increment}"/>
    
        
    
    "sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        "dataSource" ref="dataSource"/>
        "configLocation" value="classpath:sqlMapConfig.xml"/>
        "mapperLocations" value="classpath:cn/itcast/jk/mapper/*.xml"/>
    
    
        
    "txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        "dataSource" ref="dataSource"/>
    

        
    "txAdvice" transaction-manager="txManager">
        
            "find*" read-only="true" />
            "get*" read-only="true" />
            "view*" read-only="true" />
            "insert*" propagation="REQUIRED" />
            "update*" propagation="REQUIRED" />
            "delete*" propagation="REQUIRED" />
            "*" propagation="REQUIRED" />
        
    

    
        
        "execution(* cn.itcast.jk.service.*.*(..))" id="transactionPointCut"/>
        
        ref="txAdvice" pointcut-ref="transactionPointCut"/>
    
            

4.springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
"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: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-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 
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
    
    
    
    
    base-package="cn.itcast.jk.controller"/>
    
    
    "jspInternalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        "prefix" value="/WEB-INF/pages/"/>
        "suffix" value=""/>