首页 > 解决方案 > SpringBoot 抛出异常 InvalidStatementException,如何解决?

问题描述

我在 的 URL 中定义了一个 API /getAppInfo,它的参数只有一个这样的 ID:

@ResponseBody
@RequestMapping("/getAppInfo")
public ResultResponse getAppInfo(String id) {
    ResultResponse result = new ResultResponse();
    String appName = uploadedFile.getAppInfo(id);
    result.setResult(appName);
    return result;
}

uploadedFile是 Interface 的一个对象,IUploadedFileMapper这个 Mapper 反映了一个名为 的 MyBatis 映射器UploadedFileMapper.xml
然后我将以下代码写入IUploadedFileMapper.java

public String getAppInfo(String id);

之后,我将以下代码写入UploadedFileMapper.xml

<select id="getAppInfo" parameterType="java.lang.String" resultType="java.lang.String">
    select tb.name from table tb where tb.id = #{id} and tb.business_sub_type = 'APP';
</select>

当我测试这个 WebAPI 时,spring-boot 告诉我:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): example.cn.dao.IUploadedFileMapper.getAppInfo

标签: javaspringspring-bootmybatis

解决方案


您不需要table在 SQL 选择查询中

select tb.name from table tb

=>

select tb.name from tb


推荐阅读