找不到路径时如何返回状态码400

路加福音101

我有一个Spring Boot REST应用程序。当路径不存在时,我需要返回400错误请求的状态码。考虑:

This is a good url
localhost:8080/mypath?name=test

Bad Path (return status 400)
localhost:8080/mybadpath?name=test

我如何使用Spring Boot做到这一点

死侍 :

通过实施,这对于s​​pring boot-2.1.3有效ErrorController

@Controller
public class CustomErrorController implements ErrorController {

private static final String PATH = "/error";

@RequestMapping(value = PATH)
public ResponseEntity<String> error(WebRequest webRequest, HttpServletResponse response) {
    return ResponseEntity.badRequest().body("");

}

@Override
public String getErrorPath() {
    return PATH;
     }

}

主要

@SpringBootApplication
public class BotMain {

public static void main(String[] args) {
    SpringApplication.run(BotMain.class, args);
    }

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Dockerfile在找不到Java类时失败,如何将类路径或jar指定给./mvnw?

测试路径返回True,但ExtractToDirectory找不到路径

如何解决“ snapd返回状态码400:错误的请求”?

找不到条件时如何返回null?

Hyperledger Fabric在构建链码时找不到go文件

状态400和反序列化对象列表时出错。找不到默认构造函数

当找不到资源而不是HTML时如何返回404

系统找不到指定的路径:更改管理页面Django中的字段时返回错误

V-For图像路径找不到图像。使用v-for时如何添加正确的文件路径?

createTempFile时系统找不到路径

找不到bash文件中的路径时,如何在NS2中运行tcl脚本?

使用InvokeMethod创建时找不到路径

ldd找不到路径,如何添加

-bash:400 ::打开终端时找不到命令

服务器返回状态码400时,使用Powershell检索响应内容

HTTP状态码返回

找不到命令路径

测试路径返回true,但Remove-Item找不到路径

当我尝试通过Ubuntu软件中心安装Pycharm或Atom时,出现错误:捕捉到返回的状态码400:错误的请求

为什么找不到用户输入的路径返回文件?

返回码与退出状态

如何让 HttpClient 返回状态码?

找不到问题 - [错误] ld 返回 1 个退出状态

找不到文件路径时如何退出子程序?

尝试创建新文件夹时,CreateFolder 方法不断返回错误 76,“找不到路径”

Gogs + Drone:Gogs webhook 返回 400 并找不到存储库

如何获得状态码为 400 的响应 api?

axios 在进行基本认证时返回 400 的响应码

找不到数据时如何在 ReactJs 中返回原始状态