java - 在 Spring Controller 中捕获无效参数
问题描述
如果我们有这样的控制器动作
@GetMapping("/oauth2/token")
public ResponseEntity<Boolean> isTokenValid(@RequestParam("token") String token) {
//... code
}
那么我该如何处理用户未提交令牌时发生的异常。
当我有以下控制器动作时
@PostMapping("/account/{id}")
public ResponseEntity<String> updateAccount(@PathVariable("id") long id, @RequestBody AccountDTO dto) {
当无法解析 DTO 时,我该如何处理异常,并且 Jackson 在尝试从中提取 DTO 时是否验证数据?
解决方案
推荐阅读
- android - 在关闭的应用程序中收到通知时转到特定活动?
- angular - Angular 6 使用哪个 Http 模块
- css - 与 Radium 和 Material-UI 一起使用时,React 悬停样式不起作用
- json - 如何从scala中的foreach读取地图值
- c++ - QVector 总是推回 0?
- c++ - 你想如何在 cmd C++ 中打开这个文件
- python - 来自python的伪代码
- smtp - 没有收到来自 smtp 服务器的任何响应
- python - Python xlrd 和 xlwt 不会附加到现有 xls
- angular - Angular 7 formbuilder在多选获取表单上初始化值无效