The Event Management System is a Spring Boot application that allows users to manage events and venues. It provides both a web interface and a REST API for creating, reading, updating, and deleting (CRUD) events and venues.




Spring Boot is the backbone of our application, providing:
${...} for variables, *{...} for object properties<input type="text" th:field="*{name}" required>
@Entity
@Table(name="events")
public class Event {
@Id @GeneratedValue
private Long id;
private String name;
private String description;
private LocalDateTime startTime;
private LocalDateTime endTime;
@ManyToOne
private Venue venue;
}
@Entity
@Table(name="venues")
public class Venue {
@Id @GeneratedValue
private Long id;
private String name;
private String address;
private Integer capacity;
@OneToMany(mappedBy="venue")
private List<Event> events;
}
@Transactional is a crucial Spring annotation that manages database transactions. A transaction ensures that a series of database operations either all succeed or all fail together, maintaining data consistency.
@Service
@Transactional
public class EventService {
// Service methods
}
@Transactional
public Event updateEvent(Long id, Event event) {
Event existingEvent = getEventById(id); // If this fails
event.setId(existingEvent.getId());
return eventRepository.save(event); // This won't execute
}
In our Event-Venue relationship:
@Entity
public class Event {
@ManyToOne
@JoinColumn(name="venue_id")
private Venue venue;
}
Why this design?
@Entity
public class Venue {
@OneToMany(mappedBy = "venue", cascade = CascadeType.ALL)
private List<Event> events;
}
Important aspects:
EventController: Handles API requests at /api/eventsVenueController: Handles API requests at /api/venuesExample Endpoints:
// Event endpoints
GET /api/events // List all events
POST /api/events // Create new event
GET /api/events/{id} // Get specific event
PUT /api/events/{id} // Update event
DELETE /api/events/{id} // Delete event
GET /api/events/search // Search events by time range
// Venue endpoints
GET /api/venues // List all venues
POST /api/venues // Create new venue
GET /api/venues/{id} // Get specific venue
PUT /api/venues/{id} // Update venue
DELETE /api/venues/{id} // Delete venue
GET /api/venues/search // Search venues by capacity
EventViewController: Handles web pages at /eventsVenueViewController: Handles web pages at /venuesHomeController: Handles the home page at /Services contain the business logic and act as an intermediary between controllers and repositories:
EventService: Handles event-related business logicVenueService: Handles venue-related business logicKey features:
@Transactional)JPA repositories for database operations:
EventRepository: Extends JpaRepository for Event entityVenueRepository: Extends JpaRepository for Venue entityCustom queries:
// Event queries
List<Event> findByStartTimeBetween(LocalDateTime start, LocalDateTime end);
List<Event> findByVenueId(Long venueId);
// Venue queries
List<Venue> findByCapacityGreaterThanEqual(Integer capacity);
The application uses Thymeleaf templates with Bootstrap 5 for the web interface:
events/list.html: Displays all events in a tableevents/add.html: Form to create new eventsevents/edit.html: Form to edit existing eventsvenues/list.html: Displays all venues in a tablevenues/add.html: Form to create new venuesvenues/edit.html: Form to edit existing venueshome.html: Landing page with navigation to events and venuesapplication.propertiesmvn spring-boot:run to start the applicationhttp://localhost:8080/events/venues