Monday, November 23, 2026

Attendance Management Project | Spring Boot & Angular


 

Spring Boot Project Setup – Step by Step

Let's create a Spring Boot application from scratch using Java, Maven, and Spring Boot. I'll explain each step with commands, folder structure, and code examples.

Step 1: Create Spring Boot project

Open .

Choose the following configuration:








Select these dependencies:

  • Spring Web – Create REST APIs.

  • Spring Data JPA – Database operations.

  • MySQL Driver – MySQL connectivity.

  • Lombok – Reduce boilerplate code.

  • Spring Boot DevTools – Automatic restart during development.

Click Generate to download the project ZIP.


 

Step 2: Import project into IntelliJ IDEA

  1. Extract the downloaded ZIP file.

  2. Open IntelliJ IDEA.

  3. Click Open.

  4. Select the extracted project folder.

  5. Wait for Maven dependencies to download.

  6. Verify that the project builds successfully.

  7.  

Step 2:Got application.properties file and configuration the DB.





# MySQL Database Configuration

spring.datasource.url=jdbc:mysql://localhost:3306/attendance_tracker
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 

# JPA / Hibernate Configuration  
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.format_sql = true

 










Step 3:Now run the application. 

Goto->main function->run

 

working fine

 Table created inside the DB

Step 3:Now we can created the role of User. 

Create the user Entity

Step 1: Create the three pakages entities, enum, and repository.

 

Step 2:inside the entities folder create the class User

AttendanceServer.entities.User.java
@Entity
@Data
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String email;

    private String password;

    private String name;

    private UserRole userRole;

}

Step 3:inside the Enum folder create the UserRole.

 AttendanceServer/enums/UserRole.java

public enum UserRole {

        ADMIN,
        MANAGER,
        EMPLOYE
}

Step 4:inside the repository folder create the interface Repository.


Output:- Run the application and check Table created successfully.



Now we can create the Auth Service.

Step 4:Now we can created the role of Admin. 

Step 1: we will create auth service and then we will create a method to find the user by role in the user repository and at the end we will create a method to automatically create admin user.

Create Service:-
AttendanceServer/service/AuthService.java 

@Service
public class AuthService {
    @Autowired
    private UserRepository userRepository;

    @PostConstruct
    private void createAdminUser(){

        User optionalUser = userRepository.findByUserRole(UserRole.ADMIN);

        if(optionalUser == null){
            User user = new User();

            user.setName("Admin");
            user.setEmail("admin@gmail.com");
            user.setPassword("admin");
            user.setUserRole(UserRole.ADMIN);

            userRepository.save(user);
            System.out.println("Admin user Created.");
        }
        else{
            System.out.println("Admin User Already exists.");
        }


    }
}

Create Method inside the Repository:-

 AttendanceServer/repository/UserRepository.java;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    User findByUserRole(UserRole role);
}

Output:- Run the application and check Table admin data successfully updated.

 

 


No comments:

Post a Comment

If you have any problem please let me know.