D
D
DeNissss44442021-05-17 11:36:55
Java
DeNissss4444, 2021-05-17 11:36:55

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

1 answer(s)
D
Dmitry Roo, 2021-05-17
@DeNissss4444

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 question

Ask a Question

731 491 924 answers to any question