我有这段代码,无论是否找不到资源我都想抛出一个异常

Menu menu = menuService.findById(addMenuAmount.getMenuId())
                    .orElseThrow(com.tdk.web.exception.ResourceNotFoundException(“menu "  +
                            addMenuAmount.getMenuId() + " not found "));

但出现编译错误:
com.tdk.web.exception cannot be resolved to a type

最佳答案

尝试此操作,并确保可访问com.tdk.web.exception.ResourceNotFoundException

Menu menu = menuService.findById(addMenuAmount.getMenuId())
                    .orElseThrow(() -> new com.tdk.web.exception.ResourceNotFoundException("menu "  +
                            addMenuAmount.getMenuId() + " not found "));

注意lambda () ->和引号"menu "

09-25 22:04