O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Create a model class, com.packt.boot_db_demo.Person, for representing a person. We will make use of Lombok annotations to generate the getters and setters for us:
        @Data        public class Person{          private Integer id;          private String firstName;          private String lastName;          private String place;        }
  1. Let's create com.packt.boot_db_demo.PersonMapper to map the data from the database into our model class, Person:
        @Mapper        public interface PersonMapper {        }
  1. Let's add a method to get all the rows from the table. Note that the next few methods will be written inside the PersonMapper interface:
        @Select("SELECT * FROM person")        public List<Person> getPersons();
  1. Another method to get the details of a single person identified by ID is as follows: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required