欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring整合mybatis

程序员文章站 2022-05-29 13:04:50
...

本文的整合文件的目录结构:

spring整合mybatis

一:整合jar的maven坐标

<!--mybatis-->

<dependency>

<groupId>org.mybatis</groupId>

<artifactId>mybatis</artifactId>

</dependency>

<dependency>

<groupId>org.mybatis</groupId>

<artifactId>mybatis-spring</artifactId>

</dependency>

二:mybatis-config.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">
<configuration>

    <settings>
        <!--开启驼峰命令-->
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
    
</configuration>

三:spring配置加入mybatis整合内容

<!--mybatis整合-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
   <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
   <property name="dataSource" ref="dataSource"></property>
   <property name="mapperLocations" value="classpath:mybatis/mappers/**/*.xml"/>
   <!--别名配置,简化mapper的xml中的resultType-->
   <property name="typeAliasesPackage" value="com.xucj.pojo"/>
</bean>
<!--自动扫描包内的mapper-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
   <property name="basePackage" value="com.xucj.mapper"></property>
</bean>