【问题标题】:SpringBoot threw an exception called InvalidStatementException, how to solve it?Spring Boot 抛出异常 InvalidArgumentException,如何解决?
【发布时间】:2020-11-02 06:48:21
【问题描述】:

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

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

uploadedFile 是接口IUploadedFileMapper 的一个对象,这个映射器反映了一个名为UploadedFileMapper.xml 的MyBatis 映射器。
然后我把下面的代码写到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

【问题讨论】:

  • 你可以从查询中删除分号并尝试
  • 亲爱的 Anish B.:数据库正在使用 MySQL,分号似乎不会影响程序报告Invalid bound statement (not found),对吗?
  • 好的!查询看起来没问题。我认为问题可能出在 Mapper 上。
  • 怎么说?有什么细节吗,伙计?
  • 请添加更多详细信息。添加您的 Mapper 类。

标签: java spring spring-boot mybatis


【解决方案1】:

我复制了您的代码并进行了测试。它是有效的,所以我认为您的代码是正确的

【讨论】:

  • 那么也许我的环境有一些问题。谢谢老兄。
【解决方案2】:

在 SQL 选择查询中不需要 table

select tb.name from table tb

=>

select tb.name from tb

【讨论】:

    猜你喜欢
    • 2016-09-26
    • 2019-09-19
    • 2020-02-05
    • 1970-01-01
    • 2019-01-24
    • 2018-12-30
    • 2018-06-02
    • 2021-07-02
    • 2018-06-22
    相关资源
    最近更新 更多