场景:通过调用controller层方法从数据库中做基础的查询操作,提示基础查询方法没有绑定xml中的sql,通过在对应的mapper.xml文件中添加相应的sql的确能够访问成功
问题原因:配置的SqlSessionFactory实现类org.mybatis.spring.SqlSessionFactoryBean不包含BaseMapper的功能
解决方案:将配置的SqlSessionFactory实现类org.mybatis.spring.SqlSessionFactoryBean替换成mybatis-plus或者mybatis-plus-extension相应的实现类,如下:将
<!--3.sqlsessionFactory?-->
<bean id="SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="DataSource"></property>
<!--绑定mybatis配置文件-->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!--绑定mapper.xml文件所在-->
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
</bean>
替换为
<!--3.sqlsessionFactory,使用了MybatisSqlSessionFactoryBean来让basemapper生效-->
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--绑定mybatis配置文件-->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!--绑定mapper.xml文件所在-->
<property name="mapperLocations" value="classpath:mapper1/*.xml"></property>
</bean>