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;
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM