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

1次阅读

共计 2707 个字符,预计需要花费 7 分钟才能阅读完成。

我做了一个简单的 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 {

    @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 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

为了解决这个问题,我引入了这个依赖

下面是我的项目本体结构

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

我项目配置类的代码如下所示:

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 {}

Xml 的代码





以上就是所有内容,如果需要更多信息请随时跟我说,我会第一时间补充,先谢谢各位了

正文完
 0