We'll begin by looking at the MVC Method for displaying the Post by Tag page view. We're going to retrieve the Tag object, add it to the model and be on our way. The page has a nice public-facing url of /posts/tag/some+tag.
We'll start in the PostRestController class where we retrieve a page full of posts. An example url (not shown to the user) would be
If you recall from an earlier post, all NixMash Spring Posts are tested for authorship by the current user, then sent to Velocity for parsing and formatting based on the Post Type of Link, Link Summary, etc.
When we retrieved Posts we retrieved all posts with a PostRepository FindAll(), something like
Not much to that, but here we're adding the TagId parameter and using a custom PostRepository method.
Here's our Service method where we create the PageRequest.
In the PostRepository we use the abstract Pageable Interface rather than the PageRequest object. The @Query statement is interesting, too, as it demonstrates how to retrieve parent objects based on a @ManyToMany child variable.