Answer the question
In order to leave comments, you need to log in
How to make Iterable output objects from the end to the beginning?
I have a blog section in Spring, all articles from the database are displayed there, but they are displayed from beginning to end. It turns out that if I add a new article, it will be displayed at the end already. And it is necessary to me on the contrary that would deduce from the end to the beginning. How to implement it?
@Controller
public class BlogController {
@Autowired
PostRepository postRepository;
@GetMapping("/blog")
public String blog(Model model){
Iterable<Post> allArticles = postRepository.findAll();
model.addAttribute("allArticles", allArticles);
return "/blog";
}
}
Answer the question
In order to leave comments, you need to log in
It is better to select records from the database, sorted in the order you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question