![]() |
VOOZH | about |
Spring Boot, along with Spring Data JPA and MySQL, provides a powerful stack for building robust backend applications. Maven is used for dependency management and project build automation, making development faster and more organized.
Before starting, ensure you have:
- Java (JDK 8 or above)
- Maven installed
- MySQL Server & MySQL Workbench
- IDE (IntelliJ IDEA / Spring Tool Suite)
- Basic knowledge of Spring Boot
Create a Maven project and define dependencies in pom.xml.
Project Structure:
pom.xml
Run the following SQL commands:
create database geeksforgeeks; # Creation
use geeksforgeeks #Make the database activeCREATE TABLE `Contest` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`contestName` varchar(45) NOT NULL,
`contestDescription` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
Database connection properties are set in src/main/resources/persistence.xml
persistence.xml
Configuration of EntityManagerFactory and TransactionManager
ContestAppConfig.java
Let's implement the model class.
Contest.java
Instead of writing a generic DAO class, a simple interface like below is enough. It extends CrudRepository defined by Spring Data JPA. Common CRUD operations like save(), findAll(), findById(), delete(), count() etc., are defined by the interface.
ContestRepository.java
ContestTest.java
As we have tested via contestname as well, in the first output, we saw that one contest got inserted and the same is getting used to test while testing via contestname
We can check the DB data also
Note: id field is auto-generated.