Library
Management
System
Problem Statement
The Library Managment System is a full-stack web application developed to simplify the management of
library eperations as managing books, authors, and borrower. It allows users to perform CRUD operations
and interaction through a clean, intuitive frontend powered by a Spring Boot RESTful backend.
Objectives
1.) Develop a robust and scalable library management application,
2) Allow users to manage (create, read, update, delete) books & borrower details efficiently.
3.) Implement REST APIs for backend operations,
4.) Improve frontend-backend communication through a clean user interface.
Required Software Tools
Tool purpose
[Link] For backend development
[Link] 21 GUI library
3.H2 database Lightweight database for storing inventory data
[Link] Writing and editing code
[Link] used for HTML,CSS,JAVASCRIPT
[Link] API used for fetching the data form database
[Link] mapping the database into code
CODING PARTS
[Link]/main/java – package:[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@SpringBootApplication
public class LibraryApplication {
public static void main(String[] args) {
[Link]([Link], args);
// This method will be called to initialize the database with sample books
@Bean
CommandLineRunner initDatabase(BookService service) {
return args -> {
// Adding initial sample data to the book database
[Link](new Book("Introduction to Algorithms", "Thomas H. Cormen"));
[Link](new Book("Clean Code", "Robert C. Martin"));
[Link](new Book("Design Patterns", "Erich Gamma"));
[Link](new Book("Operating System Concepts", "Abraham Silberschatz"));
[Link](new Book("Database System Concepts", "Henry F. Korth"));
[Link](new Book("Artificial Intelligence: A Modern Approach", "Stuart Russell"));
[Link](new Book("Computer Networks", "Andrew S. Tanenbaum"));
[Link](new Book("Modern Operating Systems", "Andrew S. Tanenbaum"));
[Link](new Book("The Pragmatic Programmer", "Andrew Hunt"));
[Link](new Book("Structure and Interpretation of Computer Programs", "Harold
Abelson"));
[Link](new Book("Compilers: Principles, Techniques, and Tools", "Alfred V. Aho"));
[Link](new Book("Computer Architecture", "John L. Hennessy"));
[Link](new Book("Introduction to the Theory of Computation", "Michael Sipser"));
[Link](new Book("The Art of Computer Programming", "Donald E. Knuth"));
[Link](new Book("Java: The Complete Reference", "Herbert Schildt"));
[Link](new Book("Effective Java", "Joshua Bloch"));
[Link](new Book("Python Crash Course", "Eric Matthes"));
[Link](new Book("You Don't Know JS", "Kyle Simpson"));
[Link](new Book("Head First Design Patterns", "Eric Freeman"));
[Link](new Book("Code: The Hidden Language of Computer Hardware and Software",
"Charles Petzold"));
};
[Link]:[Link]
package [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
@RestController
@RequestMapping("/api/books")
@CrossOrigin
public class BookController {
private final BookService service;
public BookController(BookService service) {
[Link] = service;
@GetMapping
public List<Book> getAllBooks() {
return [Link]();
@GetMapping("/{id}")
public Optional<Book> getBookById(@PathVariable Long id) {
return [Link](id);
@PostMapping
public Book addBook(@RequestBody Book book) {
return [Link](book);
@DeleteMapping("/{id}")
public void deleteBook(@PathVariable Long id) {
[Link](id);
@PutMapping("/{id}")
public Book updateBook(@PathVariable Long id, @RequestBody Book book) {
return [Link](id, book);
[Link]:[Link]
package [Link];
public class Book {
private Long id;
private String title;
private String author;
private boolean available = true;
public Book() {
public Book(String title, String author) {
[Link] = title;
[Link] = author;
public Book(Long id, String title, String author, boolean available) {
[Link] = id;
[Link] = title;
[Link] = author;
[Link] = available;
}
public Long getId() { return id; }
public void setId(Long id) { [Link] = id; }
public String getTitle() { return title; }
public void setTitle(String title) { [Link] = title; }
public String getAuthor() { return author; }
public void setAuthor(String author) { [Link] = author; }
public boolean isAvailable() { return available; }
public void setAvailable(boolean available) { [Link] = available; }
[Link]:[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Service
public class BookService {
private final JdbcTemplate jdbcTemplate;
public BookService(JdbcTemplate jdbcTemplate) {
[Link] = jdbcTemplate;
public List<Book> getAllBooks() {
return [Link]("SELECT * FROM book", new BeanPropertyRowMapper<>([Link]));
public Optional<Book> getBookById(Long id) {
List<Book> books = [Link]("SELECT * FROM book WHERE id = ?", new
BeanPropertyRowMapper<>([Link]), id);
return [Link]().findFirst();
public Book addBook(Book book) {
[Link]("INSERT INTO book (title, author, available) VALUES (?, ?, ?)", [Link](),
[Link](), [Link]());
return book;
public void deleteBook(Long id) {
[Link]("DELETE FROM book WHERE id = ?", id);
public Book updateBook(Long id, Book book) {
[Link]("UPDATE book SET title = ?, author = ?, available = ? WHERE id = ?",
[Link](), [Link](), [Link](), id);
[Link](id);
return book;
}
}
[Link]/main/resources/static
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Library Management</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<div class="container">
<h1>Library Management System</h1>
<h2>Books</h2>
<!-- Form to add new book -->
<div class="form-container">
<h3>Add New Book</h3>
<form id="add-book-form">
<input type="text" id="title" placeholder="Book Title" required />
<input type="text" id="author" placeholder="Book Author" required />
<button type="submit">Add Book</button>
</form>
</div>
<!-- List of books -->
<h3>Books in Library</h3>
<ul id="book-list"></ul>
</div>
<script src="[Link]"></script>
</body>
</html>
[Link]
/* Reset some basic styles */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
/* Container styles */
.container {
width: 80%;
margin: auto;
padding: 20px;
/* Title styles */
h1 {
text-align: center;
color: #333;
/* Form styles */
.form-container {
margin-bottom: 20px;
form input {
padding: 8px;
margin: 5px;
width: 200px;
font-size: 16px;
form button {
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
form button:hover {
background-color: #45a049;
/* Book list styles */
ul {
list-style-type: none;
padding: 0;
li {
padding: 10px;
background-color: #f9f9f9;
margin: 5px;
border: 1px solid #ddd;
[Link]
// Get the form and elements
const addBookForm = [Link]('add-book-form');
const bookList = [Link]('book-list');
// API URLs
const apiUrl = '[Link]
// Function to fetch books from the API
async function getBooks() {
try {
const response = await fetch(apiUrl);
const books = await [Link]();
displayBooks(books);
} catch (error) {
[Link]('Error fetching books:', error);
// Function to display books in the list
function displayBooks(books) {
[Link] = '';
[Link](book => {
const li = [Link]('li');
[Link] = `${[Link]} by ${[Link]}`;
[Link](li);
});
// Function to handle form submission (Add Book)
[Link]('submit', async (event) => {
[Link]();
const title = [Link]('title').value;
const author = [Link]('author').value;
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: [Link]({ title, author })
});
if ([Link]) {
getBooks(); // Refresh the list after adding
[Link]();
} else {
alert('Failed to add the book');
} catch (error) {
[Link]('Error adding book:', error);
});
// Initial fetch of books
getBooks();
[Link] marven project add dependencies in H2 database to the [Link]
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
Configuration
# H2 Database Configuration
[Link]=jdbc:h2:mem:testdb
[Link]=[Link]
[Link]=sa
[Link]=
# JPA Settings
[Link]-platform=[Link].H2DB
[Link]-sql=true
[Link]-auto=update
# Enable H2 Console
[Link]=true
[Link]=/h2-console
Run Application
1. Build and run the project:via cmd or console window
./mvnw spring-boot:run
or using Gradle
./gradlew bootRun
[Link] H2 Console:
o URL: [Link]
o JDBC URL: jdbc:h2:File:testdb
o Username: sa
o Password: (leave blank)
📬 Sample REST Endpoints(REST API CONFIGURATION)
HTTP Method URL Description
GET Get all entities
/api/entities
POST /api/entities Create a new entity
/api/entities/
GET Get entity by ID
{id}
/api/entities/
PUT Update entity
{id}
/api/entities/
DELETE Delete entity
{id}
Sample output