I'm running a query using ActiveJdbc
List<Game> games = District.findAll("where createor_id = ?", creatorId);
And according o the documentation the query is triggered when I do this
for (Game game : games) {
//do things with result
}
But I want to put the result in a ModelMap in order to use in in the jstl view (Spring mvc 4). So How can I trigger the query? right now in order to trigger the query I have to do
game.size();
But I guess it's an optimal solution.
You should not worry about when the list will make a trip to the database. If you just pass the games
object to the JSP, then it will make DB call during rendering of the page. Also, you do not need to make additional ModelMap, just pass a list to a view.
If you insist on passing maps to JSP, you can do this:
List<Map> games = District.findAll("where createor_id = ?", creatorId).toMaps();
I hope it helps!