java - Eclipse Maven Rest Api:错误:无法将 UserNotFoundException 解析为类型。如何解决这个问题?
问题描述
这是完整的代码。它在 UserNotFoundException 处引发错误。
@RestController
public class UserResource {
//GET /users/{id}
//retrieveUser(int id)
@GetMapping("/users/{id}")
public User retrieveUser(@PathVariable int id) {
User user = service.findone(id);
if(user==null)
throw new UserNotFoundException("id-"+ id); //this throwing the error.
return user;
}
}
解决方案
UserNotFoundException
听起来像是您自己定义的异常。所以我想你必须导入它:
import yourpackage.UserNotFoundException
推荐阅读
- javafx - 什么是合适的 JavaFX 容器来存储标签?
- groovy - 使用 groovy 解析 json 响应时出现错误
- c# - Entity Framework Core 2.2 中的一对一或零映射
- java - 提交带有回调的可调用任务时 ExecutorService 的工作原理
- javascript - 关于 JS 中柯里化的好处
- sql - 如何优化/重新考虑分区查询的排名
- reactjs - 我可以阻止通过 url 导航到视图但仍允许以编程方式路由吗?
- ios - 当我不断向视图添加标签时,滚动视图不起作用
- jquery - JQuery DataTables 不能完全正确地与 ASP.NET GridView 分页一起工作(仅搜索当前页面)
- powershell - 整理组合命令的输出