二、SSM的整合(Dao、Mybatis、Service、MVC、ApplicationContext)


一、整合总体结构

二、ApplicationContext(应用上下文)

        连接各(Dao、Mybatis、Service、MVC)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-dao.xml">
    "classpath:spring-service.xml">
    "spring-mvc.xml">

三、Dao(数据库层)

    连接数据库的配置(database)

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=false
jdbc.username=root
jdbc.password=123456

   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:aop="http://www.springframework.org/schema/context"
       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">

    

    "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}">
    

    
    "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="dao">
    


四、Mybatis配置

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



    

   
    
        "pojo"/>
    
    
    
        class="dao.BooksMapper">
        class="dao.UserBooks">
        class="dao.MarketMapper">
    


五、Service(服务层)

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


    
    base-package="service">

    
    "BooksServiceImpl" class="service.BooksServiceImpl">
        "booksMapper" ref="booksMapper">
    

    "UserService" class="service.UserServiceImpl">
        "userBooks" ref="userBooks">
    

    "MarketService" class="service.MatketServiceImpl">
        "marketMapper" ref="marketMapper">
    

    
    "transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        "dataSource" ref="dataSource">
    

    

六、MVC(JavaMVC的配置)

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


    
    base-package="service">

    
    "BooksServiceImpl" class="service.BooksServiceImpl">
        "booksMapper" ref="booksMapper">
    

    "UserService" class="service.UserServiceImpl">
        "userBooks" ref="userBooks">
    

    "MarketService" class="service.MatketServiceImpl">
        "marketMapper" ref="marketMapper">
    

    
    "transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        "dataSource" ref="dataSource">
    

    
SSM