MyBatis-Spring-SpringMVC整合

2020-12-13 03:39

阅读:601

标签:bind   resources   edit   ppi   undle   日志系统   XML   mapping   encoding   

整合项目地址:https://github.com/mybatis/spring

一. 依赖包:

   》1.SpringMVC依赖包:

 


org.springframework
  spring-web
  5.1.7.RELEASEorg.springframework
  spring-webmvc
  5.1.7.RELEASEcommons-fileupload
  commons-fileupload
  1.4commons-io
  commons-io
  2.6com.fasterxml.jackson.core
  jackson-databind
  2.9.9com.fasterxml.jackson.core
  jackson-core
  2.9.9com.fasterxml.jackson.core
  jackson-annotations
  2.9.9javax.servlet
  javax.servlet-api
  4.0.1providedjavax.servlet.jsp
    javax.servlet.jsp-api
    2.3.3provided

 

  》2.Spring依赖包:


org.springframework
    spring-context
    5.1.7.RELEASEorg.springframework
    spring-core
    5.1.7.RELEASEorg.springframework
    spring-beans
    5.1.7.RELEASEorg.springframework
    spring-context-support
    5.1.7.RELEASEorg.springframework
    spring-aop
    5.1.7.RELEASEorg.springframework
    spring-aspects
    5.1.7.RELEASEorg.springframework
    spring-jdbc
    5.1.7.RELEASEorg.springframework
    spring-tx
    5.1.7.RELEASEorg.springframework
    spring-orm
    5.1.7.RELEASEmysql
    mysql-connector-java
    5.1.47com.mchange
    c3p0
    0.9.5.4org.apache.logging.log4j
    log4j-core
    2.11.2org.slf4j
    slf4j-api
    1.7.26org.slf4j
    slf4j-log4j12
    1.7.26testorg.springframework
    spring-test
    5.1.7.RELEASEtestjunit
    junit
    4.12test

  》3.MyBatis依赖包:


org.mybatis
    mybatis
    3.5.1org.mybatis
    mybatis-spring
    2.0.1

二、配置文件:创建Spring、SpringMVC、MyBatis的配置文件

  》1.创建MyBatis的配置文件(mybatis-config.xml)以及映射文件(mapper):

 

  》2.Spring的配置文件:(applicationContext.xml)

    


       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvn="http://www.springframework.org/schema/mvc"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
       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 http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd">

    
    package="cn.ll.action,cn.ll.dao,cn.ll.service"/>
    
    class="com.mchange.v2.c3p0.ComboPooledDataSource">
        class="org.springframework.jdbc.core.JdbcTemplate">
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        class="org.mybatis.spring.SqlSessionFactoryBean" >
        
        package="cn.ll.dao" />

 

  》3.SpringMVC的配置文件:(spring-mvc.xml)


       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvn="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">
    
    package="cn.ll.action" />
    
    default-servlet-handler />
    
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        class="org.springframework.context.support.ResourceBundleMessageSource">
        cn.ll.redis.message.pagescn.ll.redis.message.messageclass="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        
        class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" >
        plugins/errors

  》4.在web.xml中启动Spring和SpringMVC:


         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_4_0.xsd"
         version="4.0">
    
    contextConfigLocationclasspath:spring/application.xmlclass>org.springframework.web.context.ContextLoaderListenerclass>
    dispatcherServletclass>org.springframework.web.servlet.DispatcherServletclass>
        contextConfigLocationclasspath:spring/spring-mvc.xml1dispatcherServlet/characterEncodingFilterclass>org.springframework.web.filter.CharacterEncodingFilterclass>
        encodingUTF-8forceEncodingtruecharacterEncodingFilter/*

 

MyBatis-Spring-SpringMVC整合

标签:bind   resources   edit   ppi   undle   日志系统   XML   mapping   encoding   

原文地址:https://www.cnblogs.com/luliang888/p/11080580.html


评论


亲,登录后才可以留言!