Tag: springboot

  • How to map Enum Types to JSON requests in Spring Boot automatically?

    Let’s say you have created a REST service which accepts a JSON request. And one of the attributes in the request can only have a range of constant values. For example , the departments an employee can belong to. And the best way to represent this , is to use an Enum. But will a…

  • How to handle pagination and sorting in Spring Data?

    Let’s say you want to handle pagination and sorting for your application and you don’t want to do the hard work of writing SQL queries or setting criteria using an ORM tool. Spring Data provides a very simple and efficient way to handle pagination and sorting. All you have to do is create a repository…

  • How to generate REST services automatically for data repositories using Spring Boot?

    There is no need to write REST service controller classes yourself if you just want to expose your databases as REST services. Spring Boot can automatically convert your database repositories into REST services. In addition to it, it returns the response in HAL format which allows you to navigate to the individual records. Let’s see…

  • How to modify a REST service response without modifying existing code in Spring Boot?

    I wanted to modify a REST service with a change in the response. The service was already doing what it was intended to do . There was a requirement to change certain things related to the representation of the response. I didn’t want to change the existing code and clutter it with this logic. So…

  • How to integrate SQLite Database with Spring Boot?

    Spring Boot doesn’t provide a straightforward way to integrate SQLite database compared to other databases such as MySQL , MongoDB etc. SQLite is the most used database engine in the world as SQLite website claims. And yet it is a surprise Spring Boot doesn’t treat it the same way as it treats other databases. To…

  • How to write custom queries in Spring Data at method level?

    Say you want to write a custom JPA query for one of your data requirements. Spring Data provides great abstraction over JPA to perform CRUD operations. You can easily retrieve entity objects from database based on field values using methods like ‘findByName’ , ‘findByNameAndAge’ etc in your interface extending Spring Data repositories. If you need…

  • How to load initial data in Spring Boot with and without defining schema?

    Let’s say that you want to populate your database with initial set of values as soon as your spring boot application starts. You may particularly need it if you are using an in memory database like H2. The process differs a bit when you define the schema yourself or let Spring Data define it. Spring…