关于IDEA工具在springboot整合mybatis中出现的Invalid bound statement (not found)问题
2017-08-14 18:42
876 查看
第一次写博客。有点小激动。
笔者因为工作需要,所以需要学习springboot和springcloud,而开发工具则是公司要求使用的IDEA2017,笔者之前的开发工具是Myeclipse.
换了工具有诸多的不适应,还在慢慢的熟悉
在学习过程中难免有些磕磕碰碰,几天下来碰到了N个问题
一直有个想法,想把学习与工作过程中的错误与灵感都记录下来,却一直苦于没有什么时间而没去动笔
今天在学习springboot与mybatis整合中,使用了注解+xml的开发.
pom.xml引的几个重要依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>1.5.6.RELEASE</version>
</dependency>
这是笔者的接口mapper
@Mapper
public interface UserMapper {
List<User> likeName(String name);
User getById(Integer id);
}
这是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.example.demo.UserMapper">
<resultMap id="userMap" type="com.example.demo.User">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="age" column="age" />
</resultMap>
<select id="getById" resultMap="userMap" parameterType="int">
SELECT *
FROM USER
WHERE ID = #{id}
</select>
</mapper>
测试文件
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class MybatisTest {
@Autowired
private UserMapper userMapper;
@Test
public void getById() throws Exception {
User user = userMapper.getById(1);
System.out.println(user);
}
}
在一切准备就绪之后,测试test,却出现了org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
这个问题,通常情况下,这是xml文件与接口mapper不对应导致的. 但我仔细检查了一遍,没有发现错误.
在查阅过相关资料后发现,IDEA对xml文件处理的方式不同. mapper.xml文件需要放置在resource这个
4000
文件夹下.
而eclipse只要mapper接口文件与mapper.xml放置在同一平级目录就行
笔者因为工作需要,所以需要学习springboot和springcloud,而开发工具则是公司要求使用的IDEA2017,笔者之前的开发工具是Myeclipse.
换了工具有诸多的不适应,还在慢慢的熟悉
在学习过程中难免有些磕磕碰碰,几天下来碰到了N个问题
一直有个想法,想把学习与工作过程中的错误与灵感都记录下来,却一直苦于没有什么时间而没去动笔
今天在学习springboot与mybatis整合中,使用了注解+xml的开发.
pom.xml引的几个重要依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>1.5.6.RELEASE</version>
</dependency>
这是笔者的接口mapper
@Mapper
public interface UserMapper {
List<User> likeName(String name);
User getById(Integer id);
}
这是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.example.demo.UserMapper">
<resultMap id="userMap" type="com.example.demo.User">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="age" column="age" />
</resultMap>
<select id="getById" resultMap="userMap" parameterType="int">
SELECT *
FROM USER
WHERE ID = #{id}
</select>
</mapper>
测试文件
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class MybatisTest {
@Autowired
private UserMapper userMapper;
@Test
public void getById() throws Exception {
User user = userMapper.getById(1);
System.out.println(user);
}
}
在一切准备就绪之后,测试test,却出现了org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
这个问题,通常情况下,这是xml文件与接口mapper不对应导致的. 但我仔细检查了一遍,没有发现错误.
在查阅过相关资料后发现,IDEA对xml文件处理的方式不同. mapper.xml文件需要放置在resource这个
4000
文件夹下.
而eclipse只要mapper接口文件与mapper.xml放置在同一平级目录就行
相关文章推荐
- IDEA中解决spring整合mybatis后使用MapperScannerConfigurer扫描mapper包时“ Invalid bound statement (not found)”错误
- spring boot 整合mybatis org.apache.ibatis.binding.BindingException: Invalid bound statement(not found)
- 当mybatis整合spring后出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- 关于spring boot整合mybatis使用oracle数据库出现could not load:oracle.jdbc.driver.OracleDriver问题的终极解决方案
- spring+mybatis整合报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- springMvc+Mybatis关于 Invalid bound statement (not found):的错误
- 关于mybatis Invalid bound statement (not found) 问题
- [小技巧]关于spring boot 整合mybatis-plus: value为null时不返回的问题。
- 关于IDEA中maven整合mybatis+spring+springMVC项目中mapper文件找不到问题的解决方案(org.apache.ibatis.binding.BindingExcepti
- IDEA中Spring Boot项目MyBaits提示Invalid bound statement (not found)错误
- 关于整合SSH,出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- 关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题
- 关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题。
- 关于Springboot整合mybatis启动的问题
- 测试spring,mybatis时出现.BindingException: Invalid bound statement (not found): com.imooc.dao.Secki
- 关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题。
- Maven项目中,关于Spring Boot 整合MyBatis时,Service层无法找到mapper接口的问题解决
- IDEA下Maven项目整合Spring和MyBatis出现jdbc.properties is invalid;前言中不允许有内容
- IntelliJ IDEA使用Maven创建Spring和Mybatis工程出现...BindingException: Invalid bound statement (not found)
- 在idea里使用SpringBoot整合MyBatis时遇到的Mapper扫描不到的问题