![]() Return studentService.getStudentById(id) creating a get mapping that retrieves the detail of a specific Student int id) creating a get mapping that retrieves all the students detail from the List getAllStudent() autowired the StudentService studentService The annotation indicates that a method parameter should be bound to the body of the web request. saveStudent(): It saves the student detail.deleteStudent(): It deletes a specific student that we have specified in the path variable.We have passed id as an argument by using the annotation The annotation indicates that a method parameter should be bound to a URI template variable. getStudent(): It returns a student detail that we have specified in the path variable.getAllStudent(): It returns a List of all Students.Mark the class as RestController by using the annotation Autowire the StudentService class by using the annotation Define the following methods:.In the StudentController class, we have done the following: We have created controller class with the name StudentController. Step 12: Create a Controller class in the package. Step 11: Create a package with the name in the folder src/main/java. mark id as primary id as column int id mark class as an class name as Table class Student Mark the class as Entity by using the annotation Mark the class as Table name by using the annotation Define each variable as Column by using the annotation.Right-click on the file -> Source -> Generate Getters and Setters. Define four variable id, age, name, and.In the Books class, we have done the following: We have created model class with the name Student. Step 10: Create a model class in the package. Step 9: Create a package with the name in the folder src/main/java. Step 8: Import the project folder into STS.įile -> Import -> Existing Maven Projects -> Browse -> Select the folder spring-boot-h2-database-example -> Finish Step 7: Extract the Jar file and paste it into the STS workspace. When we click on the Generate button, it wraps the project in a Jar file and downloads it to the local system. Step 5: Add the dependencies Spring Web, Spring Data JPA, and H2 Database. ![]() We have provided spring-boot-h2-database-example. Step 2: Select the Spring Boot version 2.3.0.M1. Let's set up a Spring Boot application with the H2 database. In the above screenshot, we have defined our own database named javatpoint. Once we have enabled the H2 console, now we can access the H2 console in the browser by invoking the URL The following figure shows the console view of the H2 database. If we want to use H2 database in an application we need to add the following dependency in pom.xml file:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |