Springboot 整合 Mybatis 错误

这篇博客主要介绍了在SpringBoot项目中遇到的两个常见错误:一是Mybatis的xml映射文件未被正确编译到目标目录导致的内部服务器错误,解决方法是在pom.xml中配置资源;二是由于Controller方法缺少@ResponseBody注解引起的HTTP 404状态,修正后能从后端获取数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1-错误信息:type = internal Server Error

        idea控制台

org.apache.ibatis.binding.BindingException: 
Invalid bound statement (not found): com.bjpowernode.springboot.mapper.StudentMapper.selectByPrimaryKey

        浏览器页面报错:state 500

    

 解决办法:

  • 默认情况下,Mybatis的xml映射文件不会编译到target的class目录下,所以我们需要在pom.xml文件中配置resource
<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.xml</include>
        </includes>
    </resource>
</resources>

2-错误信息:type=Not Found, status=404

后端 debug 发现Controller可以从后台得到数据,后来发现是 controller 中的方法未注解 @ResponseBody

浏览器页面:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值