我发送给Apifox是http://localhost:9002/goods/getByUserName?name=张三 为什么会是500哪里错了?

{ "timestamp": "2025-10-02T11:04:25.374+0000", "status": 500, "error": "Internal Server Error", "message": "Invalid bound statement (not found): com.daqin.demo251001.mapper.UserMapper.getByUserName", "path": "/goods/getByUserName" }我发送给Apifox是http://localhost:9002/goods/getByUserName?name=张三 为什么会是500哪里错了?

错误分析

根据错误信息 `Invalid bound statement (not found): com.daqin.demo251001.mapper.UserMapper.getByUserName`,这是一个MyBatis绑定异常,表示找不到对应的SQL语句。

可能原因及解决方案

1. Mapper XML文件位置或命名问题

  • 确保 [UserMapper.xml](file://D:\SUM\代码\demo251001\target\classes\generator\mapper\UserMapper.xml) 文件位于正确目录:`src/main/resources/mapper/`

  • 文件名必须与Mapper接口名一致:[UserMapper.xml](file://D:\SUM\代码\demo251001\target\classes\generator\mapper\UserMapper.xml)

2. XML文件中缺少SQL定义

在 [UserMapper.xml](file://D:\SUM\代码\demo251001\target\classes\generator\mapper\UserMapper.xml) 中添加 [getByUserName](file://D:\SUM\代码\demo251001\src\main\java\com\daqin\demo251001\mapper\UserMapper.java#L16-L16) 方法对应的SQL语句:

```xml

<select id="getByUserName" parameterType="string" resultType="com.daqin.demo251001.vo.GoodsMsgVo">

SELECT * FROM user WHERE name = #{name}

</select>

```

3. 检查Mapper接口与XML的匹配

确保以下几点:

  • UserMapper\](file://D:\\SUM\\代码\\demo251001\\src\\main\\java\\com\\daqin\\demo251001\\mapper\\UserMapper.java#L14-L17) 接口中的 \[getByUserName\](file://D:\\SUM\\代码\\demo251001\\src\\main\\java\\com\\daqin\\demo251001\\mapper\\UserMapper.java#L16-L16) 方法签名与XML中定义一致

  • XML中 `<select>` 标签的 [id](file://D:\SUM\代码\demo251001\src\main\java\com\daqin\demo251001\domain\User.java#L14-L15) 属性值为 [getByUserName](file://D:\SUM\代码\demo251001\src\main\java\com\daqin\demo251001\mapper\UserMapper.java#L16-L16)

4. 检查MyBatis配置

确认 [application.yml](file://D:\SUM\代码\demo251001\src\main\resources\application.yml) 中的MyBatis配置正确:

```yaml

mybatis-plus:

mapper-locations: classpath:mapper/*.xml

```

完成以上检查和修改后重启应用,问题应该能够解决。

相关推荐
白仑色16 小时前
java中的anyMatch和allMatch方法
java·linux·windows·anymatch·allmatch
刃神太酷啦16 小时前
C++ list 容器全解析:从构造到模拟实现的深度探索----《Hello C++ Wrold!》(16)--(C/C++)
java·c语言·c++·qt·算法·leetcode·list
wearegogog12316 小时前
C# 条码打印程序(一维码 + 二维码)
java·开发语言·c#
码农阿豪16 小时前
用 PlaylistDL 攒私人音乐库?加个 cpolar,出门在外也能随时听!
java
LaughingDangZi16 小时前
vue+java分离项目实现微信公众号开发全流程梳理
java·前端·后端
爬山算法16 小时前
Netty(14)如何处理Netty中的异常和错误?
java·前端·数据库
云和数据.ChenGuang16 小时前
自动化运维工程师之ansible启动rpcbind和nfs服务
运维·服务器·运维技术·数据库运维工程师·运维教程
yimengsama16 小时前
VMWare虚拟机如何连接U盘
linux·运维·服务器·网络·windows·经验分享·远程工作
松涛和鸣16 小时前
32、Linux线程编程
linux·运维·服务器·c语言·开发语言·windows
Running_slave16 小时前
聊聊TCP滑窗的一些有趣“病症”
前端·网络协议·tcp/ip