学无先后,达者为师

网站首页 编程语言 正文

SpringBoot项目中的500错误

作者:TAIKI_daiji 更新时间: 2024-03-28 编程语言

SpringBoot项目中的500错误

自己莫名其妙踩的坑

注意看!就是这段代码!!

@PutMapping("/sub/{id}")
private Result subtract(@PathVariable("id") Integer id){
    return couponService.subtractById(id);
}

在本地测试接口,发的请求是这一条http://localhost:8080/sub/1

报了500错误!!

保险起见还是把mapper和service层检查了一遍。

这个项目用的是MybatisPlus,mapper层没用自己写的东西,sql应该是不会出错的。

然后在service层方法入口的下一行放了测试用的输出

log.info("*****************************************************************");

发现这条语句始终没有输出过

然后又不停地在换请求参数,PathVariable和Parameter,PostMapping和PutMapping都试了一遍

接口测试都是同样的报错,500!

最后一行一行检查,才发现是Controller中方法误用private修饰而导致接口500错误

附上正确代码

    @PutMapping("/sub")
    private Result subtract(@Parameter Integer id){
        return couponService.subtractById(id);
    }

想给自己来一拳

Controller中接口方法都要用public修饰,不然会导致500

*** 最后附上REST风格的请求设计规范(来自某马)***

在这里插入图片描述

原文链接:https://blog.csdn.net/qq_39354855/article/details/136890574

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新