spring-mybatis配置文件中指定实体类映射文件

在SSM框架下开发,通常需要配置Spring Mybatis之间联系的配置文件,其中一项为
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
       <property name="dataSource" ref="dataSource" />
       <!-- <property name="configLocation" value="classpath:mybatis-config.xml" />  -->
       <property name="mapperLocations" value="classpath:com/example/mapping/**/*.xml" />
</bean>

其中的configLocation和mapperLocations可以同时指定某一包以及子包下面的所有配置文件,mapperLocations和configLocation有一个即可,当需要为实体类指定别名时,可指定configLocation属性,再在mybatis总配置文件中采用mapper引入实体类映射文件


若是使用configLocation,其中mybatis-config.xml的格式为(具体指定每一个mapper)

<?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>
	<mappers>
		<mapper resource="com/example/mapping/IncomeMapper.xml" />
		<mapper resource="com/example/mapping/ExpenditureMapper.xml" />
		<mapper resource="com/example/mapping/UserMapper.xml" />
	</mappers>
</configuration> 


也可以不具体指定mapper,而是使用mapperLocations,其格式为classpath:com/example/mapping/**/*.xml。 -- **表示任意级目录,上例可以扫描com.example.mapping目录下的各级目录下的xml文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值