Springboot 项目测试请求时总是报 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found),求大佬帮忙解决

查看 13|回复 1
作者:tiRolin   
我做了一个简单的 CURD 项目,但是这个项目测试接口时却总是报
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
这个问题困扰了我快一天了,我一直没能解决它
下面是我的部分 Controller 和 Service 相关的代码
Controller 的部分
@RestController
@RequestMapping("/private/user/baseTestUser")
public class BaseTestUserController {
    @Autowired
    private BaseTestUserService baseTestUserService;
    /**
     * 新增用戶
     * @param baseTestUserInsertBo 用戶插入請求對象
     * @return 新增用戶 id
     */
    @ApiOperation("增加用戶方法")
    @PostMapping("/add")
    @AvoidRepeatableCommit
    public ResponseDTO insert(
            @ApiParam(name = "BaseTestUserInsertBo",value = "用戶插入實體對象")
            @RequestBody @Valid BaseTestUserInsertBo baseTestUserInsertBo) {
        return ResponseDTO.ok(baseTestUserService.insert(baseTestUserInsertBo));
    }
}
Service 的部分
@Service
public class BaseTestUserService extends BaseService[B] {
    @Autowired
    private BaseTestUserMapper baseTestUserMapper;
    @Transactional
    public Long insert(BaseTestUserInsertBo baseTestUserInsertBo) {
        BaseTestUser baseTestUser = baseTestUserInsertBo.toEntity();
        baseTestUser.setRoleID(1);
        exist(baseTestUser);
        insert(baseTestUser);
        return baseTestUser.getId();
    }
    /**
     * 用戶名唯一性檢查
     * @param baseTestUser 用戶對象
     */
    private void exist(BaseTestUser baseTestUser) {
        QueryWrapper[B] queryWrapper = new QueryWrapper();
//        queryWrapper.lambda().ne(baseTestUser.getId() != null, BaseTestUser::getId, baseTestUser.getId());
        queryWrapper.lambda().eq(BaseTestUser::getUsername, baseTestUser.getUsername());
        long count = this.count(queryWrapper);
        BaseTestUserErrorEnum.BASE_USER_EXIST_SAME_NAME_ERROR.isTrue(count>0);
    }
}
我觉得我的代码部分是没什么问题的,但是每次代码运行到 this.count(queryWrapper);这一行的时候就会报我上面所说的异常,但是我项目编译可以通过,我甚至可以按住 ctrl 进入到 count 的字节码文件里,按说是没问题的,但是却会报问题,我尝试了很多方法都没能解决这个问题,我实在是没法了,所以我来问问各位
下面是一些有关于我项目的更多内容,方便各位解决问题
首先我使用的 jdk 版本是 21 ,maven 版本是 3.5.3
我在 pom 文件中引入了 mybatis 相关依赖,具体内容如下
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            3.0.3
        
事实上,我即使不引入这个依赖,在我的依赖中也已经存在 mybatis 和 mybatisplus 的相关内容了,但是我没引入这个依赖之前启动项目会报
Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
为了解决这个问题,我引入了这个依赖
下面是我的项目本体结构

我项目配置类的代码如下所示:
spring.application.name=jarlearning21
spring.datasource.url=jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
server.port=8081
mybatis.mapper-locations= classpath*:org/example/jarlearning21/user/mapper/**/*.xml
mybatis-plus.type-aliases-package=org.example.jarlearning21.user.model.po
启动类的代码如下
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@MapperScan("org.example.jarlearning21.user.mapper")
public class Jarlearning21Application {
    public static void main(String[] args) {
        SpringApplication.run(Jarlearning21Application.class, args);
    }
}
Mapper 的代码
public interface BaseTestUserMapper extends BaseMapper[B] {}
Xml 的代码
以上就是所有内容,如果需要更多信息请随时跟我说,我会第一时间补充,先谢谢各位了
tiRolin
OP
  
这几天在这里问的问题可能有些多,多有打扰,但是我都是确实解决不了才来问各位的,我在这里问的问题基本我自己是尝试过许多办法去解决都还行不通我才来问的,不是说单纯把各位当做什么好用的工具了有事就来问,我是实在没办法了才来向各位请教的
如有打扰还望多多包涵,实在不好意思
您需要登录后才可以回帖 登录 | 立即注册

返回顶部