1
I have a method in my DAO class that returns a general list of the table:
public List<ObjetoRisco> findAll() {
return manager.createQuery("select o from ObjetoRisco o", ObjetoRisco.class).getResultList();
}
In my class Controller
, I’m having a hard time filtering out the maximum value of the ID column using the Java 8 API.
The closest I came to the desired result was this way:
Optional<Integer> maxId = objetoRiscoDao.findAll().stream().map(ObjetoRisco::getId).max(Integer::compare);
modelAndView.addObject("maxId", maxId);
But when I call on my JSP ${maxId}
, I receive in response Optional[270]
.
In fact the 270 is the last id, but I’m not getting it as whole so I can manipulate it, like,: ${maxId + 1}
.
@Maurydeveloper No need to add ```java in the code blocks. Since the question already has the [java] tag, the syntax Highlight is applied automatically, without having to specify the language. See more details in the FAQ: https://meta.stackexchange.com/q/184108/401803
– hkotsubo