springboot java.util.NoSuchElementException: No value present 异常处理

使用jpa查询的时候,如果查询不到数据,就会返回这个错误,下面是处理方法。

    @Override
    public User findByEmail(String email) {
        User user = new User();
        user.setEmail(email);
        Example<User> example = Example.of(user);
        Optional<User> optional = userDao.findOne(example);

        return optional.isPresent() ? optional.get(): null;
    }