问题:
利用maven搭建SSM框架时,出现了org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题。
解决思路:
- 逆向工程生成的mapper.java和mapper.xml一般不会错,除非自己配置错误
配置SqlSessionFactory以及动态代理接口 <!-- SqlSessionFactory配置 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 加载mybatis核心配置文件 --> <property name="configLocation" value="classpath:sqlMapConfig.xml" /> <!-- 别名包扫描 --> <property name="typeAliasesPackage" value="com.rvelamen.springmvc.pojo" /> </bean> <!-- 动态代理,第二种方式:包扫描(推荐): --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- basePackage多个包用","分隔 --> <property name="basePackage" value="com.rvelamen.springmvc.mapper" /> </bean>
3.
自动扫描了resources目录下的文件,无法扫描*Mapper.xml文件,同时无法将配置文件加载到classes目录 <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources>