Java Eclipse Maven Rest Api:错误:无法将UserNotFoundException解析为类型。如何解决这个问题?
这是完整的代码。它在UserNotFoundException上抛出一个错误Java Eclipse Maven Rest Api:错误:无法将UserNotFoundException解析为类型。如何解决这个问题?,java,eclipse,spring-boot,maven,Java,Eclipse,Spring Boot,Maven,这是完整的代码。它在UserNotFoundException上抛出一个错误 @RestController public class UserResource { //GET /users/{id} //retrieveUser(int id) @GetMapping("/users/{id}") public User retrieveUser(@PathVariable int id) { User user =
@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
UserNotFoundException
听起来像是您自己定义的异常。所以我想你必须导入它:
import yourpackage.UserNotFoundException
UserNotFoundException
听起来像是您自己定义的异常。所以我想你必须导入它@Jasmete让我自私,并将其作为得分的答案发布;-)UserNotFoundException
听起来像是您自己定义的异常。所以我想你必须导入它@Jasmete让我自私,并将其作为得分的答案发布;-)