IDEA org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
参考文章:https://blog.youkuaiyun.com/qq_37746483/article/details/82877323
mapper的xml 文件与接口没有放在同一个地方。
解决方案:POM文件里面加入如下,maven clean 然后compile 就可以看到target里面,两个都有了,xml和class文件
<resources>
<resource>
<directory>src/main/java/</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
报错二:
Consider defining a bean of type 'com.example.springbootdruid.mapper.UserMapper' in your configurati
参考文章:https://cloud.tencent.com/developer/article/1386113
启动的时候,加入如下即可
@SpringBootApplication//标识该项目为springboot的应用
@MapperScan("com.xk.mapper")
配置文件里面加上
mybatis.mapperLocations=classpath:mapper/*.xml
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
spring boot 第六节 注解版
步骤:就是删掉xml文件,然后接口文件修改为注解类的。
package com.xk.mapper;
import com.xk.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface UserMapper {
@Insert("insert into t_user(name) values(#{name})")
@Options(useGeneratedKeys=true,keyColumn="id",keyProperty="id")
//保存一个对象
void save(User user);
@Delete("delete from t_user where id = #{id}")
//移除一个对象
void remove(Long id);
//更新对象
@Update("update t_user set name = #{name} where id = #{id}")
void update(User user);
@Select("select * from t_user where id = #{id}")
//通过Id加载一个对象
User loadById(Long id);
@Select("select * from t_user")
//加载所有的对象
List<User> loadAll();
}