mybatis和spring整合
typeAliasesPackage自動配置別名
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自動配置別名 -->
<property name="typeAliasesPackage" value="com.m" />
<!-- <property name="typeAliasesSuperType" value="com.m.entity.Book"/> -->
<!-- mybatis mapper配置文件 -->
<property name="mapperLocations" value="classpath:com/m/mappers/*.xml" />
</bean>
當你設置這個 ,那麼在Mybatis的Mapper文件裏面就可以直接寫對應的類名 而不用寫全路徑名了
例
設置前:parameterMap=“com.m.City”
設置後:
設置後:
<update id="updateCity" parameterMap="City">
update
city
set
<if test="provinceId!=null">
province_id = #{provinceId},
</if>
<if test="cityName!=null">
city_name = #{cityName},
</if>
<if test="description!=null">
description = #{description}
</if>
where
id = #{id}
</update>