Build a Markdown-based Blog with Spring Boot — Part 2

Build a Markdown Blog with Spring Boot Part 2

Defining repositories

Spring Data provides several Repository abstractions that aim at reducing the amount of human-generated code for data-access layers. Two of such abstractions that we need for our blog are CrudRepository and PagingAndSortingRepository.

AuthorRepository interface
PostRepository interface

Defining controllers

Now onto defining controllers for the blog. These will handle requests to our web application and are responsible for delivering the appropriate view to the client.

RootController

RootController will be mapped to handle GET / requests.

RootController class

PostController

PostController will be mapped to handle GET /posts/* requests.

PostController class
PostController class with getPaginatedPosts method
PostController class with getPostById method

Code

This is it for part 2. Stay tuned for more parts where we continue building our Markdown blog.

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store