如题,求解答,这是我在学习springboot整合mybatisplus时遇到一个困惑的问题,请教一下各位,这是导入的mybatisplus包,
在配置类MybatisPlusAutoConfiguration下配置好了mapperLocations
@Configuration
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
@ConditionalOnSingleCandidate(DataSource.class)
@EnableConfigurationProperties({MybatisPlusProperties.class})
@AutoConfigureAfter({DataSourceAutoConfiguration.class, MybatisPlusLanguageDriverAutoConfiguration.class})
public class MybatisPlusAutoConfiguration implements InitializingBean
public class MybatisPlusProperties {
private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
private String configLocation;
private String[] mapperLocations = new String[]{"classpath*:/mapper/**/*.xml"};
按理说应该在任意包的类路径下的所有mapper文件夹下任意路径下的所有xml都是sql映射文件。
但是当我在配置文件中没有配置mapperLocations时,,
则写在这个文件夹的mapper文件无法映射,
控制台输出
Invalid bound statement (not found): com.school.boot.mapper.UserMapper.getUser
这是我的UserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.school.boot.mapper.UserMapper">
<select id="getUser" resultType="com.school.boot.bean.User">
select * from user where id = #{id}
</select>
</mapper>
这是我的UserMapper.java
package com.school.boot.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.school.boot.bean.User;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface UserMapper extends BaseMapper<User> {
// @Select("select * from user where id = #{id}")
User getUser(Integer id);
}