mybatisplus自动配置了mapperLocations但是为什么仍无法映射?
如题,求解答,这是我在学习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);
}
在此之外使用@select注解以及使用BaseMapper的方法都可以。
回答:
private String[] mapperLocations = new String[]{"classpath*:/mapper/**/*.xml"};
你的是/mybaits/mapper,是不是这里出问题了?
以上是 mybatisplus自动配置了mapperLocations但是为什么仍无法映射? 的全部内容, 来源链接: utcz.com/p/944382.html