spring-mybatis.xml整合配置如下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
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-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<!-- spring整合Mybatis的配置,其实主要是mybatis的相应配置 -->
<!--
sqlSession工厂 mapper的接口配置
-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 加载全局的配置文件 -->
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
<!-- 配置mapper的扫描,找到所有的mapper.xml映射文件。编码时放开注释,如果放开需要在mapper中写一个mapper也是可以的 -->
<!-- <property name="mapperLocations" value="classpath:mybatis/mapper/*.xml"></property> -->
<!-- 配置类型别名 -->
<property name="typeAliasesPackage" value="com.usermanage.pojo"></property>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--配置mapper接口所在路径,扫描路径下的所有的mapper接口 如果配置多个mapper的包,使用逗号进行分割
-->
<!--在mybatis当中,dao层与mapper是一样的,只是不同地方叫法不一样,mapper.xml是写sql的,是用来操作数据库的 -->
<property name="basePackage" value="cn.usermanage.dao,cn.usermanage.mapper" />
</bean>

</beans>

原文链接:https://blog.csdn.net/qq_30764991/article/details/79816261

posted @ 2021-11-13 20:21  xjspyx  阅读(181)  评论(0)    收藏  举报