Simple SpringBoot CRUD App
Simple SpringBoot CRUD App
This is a basic Spring Boot application that performs Create, Read, Update, and Delete
(CRUD) operations
on a Student entity using an in-memory H2 database. It uses Spring Web and Spring Data
JPA.
Add these dependencies in your pom.xml file to use Spring Boot, Web, JPA, and H2 database:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
This class defines a Student with ID, name, and course. It maps to the database table.
@Entity
public class Student {
@Id @GeneratedValue
private Long id;
private String name;
private String course;
// getters and setters here
}
4. Repository (StudentRepository.java)
This interface allows Spring Data JPA to manage Student data without writing SQL.
5. Controller (StudentController.java)
This class handles API calls like GET, POST, PUT, and DELETE for students.
@RestController
@RequestMapping("/students")
public class StudentController {
@Autowired StudentRepository repo;
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update