I do data processing that I can't or don't want to do on the database level, I use streams:
I need to filter users according to some algorithms and then set the name for the users found to database.
userRepository
.findAll()
.stream()
.filter(isFourierTransform())
.forEach(i ->i.setName("Fourier");
Unfortunately, the above code does not save anything to database.
Below the working code
List<User>user=userRepository
.findAll()
.stream()
.filter(isFourierTransform())
.collect(Collectors.toList());
for(User user:u)
{
user.setName("")
}
userRepository.save(user);
how to make the first example work?
userRepository
.findAll()
.stream()
.filter(isFourierTransform())
.map(i -> { i.setName("Fourier"); return i;}
.forEach(userRepository::save)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With