- 在classpath后面的 * 必不可少,缺少型号的话后面的通配符不起作用。*表示可以表示任意多级目录, 表示多个任意字符
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:sqlMapConfig.xml"></property>
<property name="mapperLocations"value="classpath*:com/huaxin/**/*Mapper.xml"></property>
</bean>
- Spring整合JUnit4测试时,使用注解引入多个配置文件
一般情况下:
@ContextConfiguration(Locations="../applicationContext.xml")
多个文件时,可用{}
@ContextConfiguration(locations = { "classpath*:/spring1.xml", "classpath*:/spring2.xml" })
- 异常:Invocation of destroy method ‘close’ failed on bean with name’sqlSession’:java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSession
去掉xml文件中
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
- 异常:There is no getter for property named ‘id’ in class
在使用mybaitis传参数的时候,如果仅传入一个类型为String的参数,那么在 xml文件中应该使用_parameter来代替参数名。
- mapper.xml中 jdbcType的作用
使用MyBatis框架做更新操作时,在该字段需要更新的内容为空时,就会出现1111错误,也就是无效的列类型,这个时候你就要使用jdbcType。