Skip to content

wynaung19/Java_Spring

Repository files navigation

SKU Board System - Spring Boot Web Application

A production-ready web application built with Spring Boot 3.5.8 featuring secure user authentication, multi-user session management, and a full-featured board system with pagination and search capabilities.
Developed as part of Java Spring course at Sungkyul University demonstrating enterprise-level web development patterns.


πŸ“‹ Project Overview

This is a full-stack Spring Boot application that implements:

  • Secure user authentication with BCrypt password encryption
  • Multi-user session management using UUID-based session tracking
  • Board/Blog system with CRUD operations, pagination, and search
  • File upload capabilities with configurable size limits
  • Input validation using Jakarta Bean Validation
  • Production-ready features including session management and security best practices

Developer: Wai Yan Naung
Framework: Spring Boot 3.5.8
Java Version: 21
Database: MySQL 8.x


🎯 Key Features

1. User Authentication & Authorization

  • Secure user registration with encrypted password storage (BCrypt)
  • Session-based authentication with UUID tracking for concurrent multi-user support
  • Login/logout functionality with proper session management
  • Protected routes requiring authentication before access

2. Board Management System

  • Create, view, and list board posts with rich metadata
  • Server-side validation for content integrity (title max 200 chars, content max 5000 chars)
  • Search functionality with case-insensitive keyword filtering
  • Pagination support (3 posts per page, configurable)
  • Automatic date formatting (dd-MM-yyyy)
  • Author name automatically assigned from logged-in user session

3. Multi-User Session Support

  • Independent session management per user using UUID
  • Concurrent user support without session conflicts
  • Each user maintains their own authenticated session
  • Secure session cookie handling with configurable timeout

4. File Upload System

  • Configurable file size limits (max 10MB per file, 30MB per request)
  • Static file serving for uploaded content
  • Secure file storage in designated upload directory

5. Production-Ready Architecture

  • Layered architecture: Controller β†’ Service β†’ Repository
  • DTO pattern for clean data transfer
  • Builder pattern for entity creation
  • Input validation with @Valid annotations
  • Exception handling for authentication failures
  • Server-side defaults for views/likes counters

πŸ—οΈ Technology Stack

Layer Technology
Backend Spring Boot 3.5.8, Spring MVC, Spring Data JPA
Frontend Thymeleaf, Bootstrap 4.5.2, HTML5, CSS3, JavaScript
Database MySQL 8.x with JPA/Hibernate ORM
Security Spring Security (BCrypt password hashing), Session Management
Build Tool Maven 3.x
Template Engine Thymeleaf
Validation Jakarta Bean Validation API
Monitoring Spring Boot Actuator
JS Libraries CounterUp, Easing, Isotope, Lightbox, OwlCarousel, Typed.js, Waypoints, WOW.js
IDE / Tools Visual Studio Code, Git, GitHub

Features


πŸ“Š Database Schema

Member Table

CREATE TABLE member (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL,  -- BCrypt encrypted
    age VARCHAR(50) NOT NULL,
    mobile VARCHAR(50) NOT NULL,
    address VARCHAR(255)
);

Board Table

CREATE TABLE board (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(200) NOT NULL,
    content TEXT(5000) NOT NULL,
    user VARCHAR(255) NOT NULL,           -- Author name (from session)
    newdate VARCHAR(50) NOT NULL,         -- Format: dd-MM-yyyy
    count VARCHAR(50) NOT NULL DEFAULT '0',   -- View count
    likec VARCHAR(50) NOT NULL DEFAULT '0',   -- Like count
    password VARCHAR(255) NOT NULL,       -- Post password (for edit/delete)
    email VARCHAR(255) NOT NULL,          -- Author email
    mobile VARCHAR(50) NOT NULL,
    name VARCHAR(255) NOT NULL,
    address VARCHAR(255),
    age VARCHAR(50) NOT NULL DEFAULT '0'
);

πŸš€ Setup & Installation

Prerequisites

  • Java JDK 21 or higher
  • MySQL Server 8.x
  • Maven 3.6+ (or use included mvnw.cmd)
  • VS Code with Spring Boot Extension Pack (recommended)

Required VS Code Extensions

  • vmware.vscode-boot-dev-pack - Spring Boot Dev Pack
  • vscjava.vscode-java-pack - Java Extension Pack
  • cweijan.vscode-mysql-client2 - MySQL Client
  • cweijan.dbclient-jdbc - Database Client

Step 1: Clone/Download Project

# Clone the repository
git clone https://github.com/wynaung19/Java_Spring.git

# Navigate to project directory
cd Java_Spring

Step 2: Configure Database

  1. Create MySQL database:
CREATE DATABASE spring CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  1. Update database credentials in src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/spring?serverTimezone=Asia/Seoul
spring.datasource.username=root
spring.datasource.password=YOUR_PASSWORD  # Change this
  1. Tables will be auto-created on first run (spring.jpa.hibernate.ddl-auto=update)

Step 3: Build Project

# Windows
mvnw.cmd clean install

# Linux/Mac
./mvnw clean install

Step 4: Run Application

Option 1: Using VS Code Spring Boot Dashboard

  • Open project in VS Code
  • Open Spring Boot Dashboard (left sidebar)
  • Click ▢️ Run button next to SkuApplication

Option 2: Using Maven Command

# Windows
mvnw.cmd spring-boot:run

# Linux/Mac
./mvnw spring-boot:run

Option 3: Using Terminal

java -jar target/sku-0.0.1-SNAPSHOT.jar

Application URL: http://localhost:8080


πŸ“ Project Structure

sku/
β”œβ”€β”€ src/main/
β”‚   β”œβ”€β”€ java/com/waiyannaung/sku/
β”‚   β”‚   β”œβ”€β”€ SkuApplication.java              # πŸš€ Application entry point
β”‚   β”‚   β”œβ”€β”€ controller/
β”‚   β”‚   β”‚   β”œβ”€β”€ BlogController.java          # πŸ“ Board CRUD & pagination
β”‚   β”‚   β”‚   β”œβ”€β”€ MemberController.java        # πŸ” Authentication & sessions
β”‚   β”‚   β”‚   β”œβ”€β”€ FileController.java          # πŸ“ File upload handling
β”‚   β”‚   β”‚   β”œβ”€β”€ BlogRestController.java      # 🌐 REST API endpoints
β”‚   β”‚   β”‚   └── SkuController.java           # πŸ§ͺ Test endpoints
β”‚   β”‚   β”œβ”€β”€ model/
β”‚   β”‚   β”‚   β”œβ”€β”€ domain/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Board.java               # πŸ“‹ Board entity (JPA)
β”‚   β”‚   β”‚   β”‚   └── Member.java              # πŸ‘€ Member entity (JPA)
β”‚   β”‚   β”‚   β”œβ”€β”€ repository/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BoardRepository.java     # πŸ—„οΈ Board data access
β”‚   β”‚   β”‚   β”‚   └── MemberRepository.java    # πŸ—„οΈ Member data access
β”‚   β”‚   β”‚   └── service/
β”‚   β”‚   β”‚       β”œβ”€β”€ BlogService.java         # πŸ’Ό Board business logic
β”‚   β”‚   β”‚       β”œβ”€β”€ MemberService.java       # πŸ’Ό Authentication logic
β”‚   β”‚   β”‚       β”œβ”€β”€ AddArticleRequest.java   # πŸ“¦ Board DTO
β”‚   β”‚   β”‚       └── AddMemberRequest.java    # πŸ“¦ Member DTO
β”‚   β”‚   └── config/                          # βš™οΈ Configuration classes
β”‚   └── resources/
β”‚       β”œβ”€β”€ application.properties           # βš™οΈ Configuration
β”‚       β”œβ”€β”€ templates/                       # 🎨 Thymeleaf views
β”‚       β”‚   β”œβ”€β”€ board_list.html             # List with pagination
β”‚       β”‚   β”œβ”€β”€ board_view.html             # Post detail view
β”‚       β”‚   β”œβ”€β”€ board_write.html            # Create post form
β”‚       β”‚   β”œβ”€β”€ login.html                  # Login page
β”‚       β”‚   β”œβ”€β”€ join_new.html               # Registration form
β”‚       β”‚   β”œβ”€β”€ join_end.html               # Success page
β”‚       β”‚   β”œβ”€β”€ index.html                  # Homepage
β”‚       β”‚   └── error_page/
β”‚       β”‚       └── article_error.html      # Error handling
β”‚       └── static/                         # 🎨 Static resources
β”‚           β”œβ”€β”€ css/                        # Bootstrap & styles
β”‚           β”œβ”€β”€ js/                         # JavaScript libraries
β”‚           β”œβ”€β”€ img/                        # Images
β”‚           └── upload/                     # User uploads
β”œβ”€β”€ pom.xml                                 # πŸ“¦ Maven dependencies
β”œβ”€β”€ mvnw.cmd / mvnw                         # Maven wrapper
└── README.md                               # πŸ“– This file

🌐 Application Routes

Public Routes

Route Method Description
/ GET 🏠 Homepage (portfolio)
/member_login GET πŸ” Login page
/join_new GET ✍️ Registration page
/api/members POST πŸ“ User registration
/api/login_check POST βœ… Authentication

Protected Routes (Login Required)

Route Method Description
/board_list GET πŸ“‹ List posts (paginated, searchable)
/board_view/{id} GET πŸ‘οΈ View single post
/board_write GET ✍️ Create post form
/api/boards POST πŸ’Ύ Submit new post
/api/logout GET πŸšͺ Logout & clear session

πŸ” Security Features

1. Password Encryption (BCrypt)

// One-way hash - cannot be decrypted
String encodedPassword = passwordEncoder.encode(rawPassword);
// Stored in DB: $2a$10$N9qo8uLOickgx2ZMRZoMye...

2. Multi-User Session Management

// Each user gets unique UUID session
String sessionId = UUID.randomUUID().toString();
session.setAttribute("userId", sessionId);        // Tracking ID
session.setAttribute("userName", member.getName()); // Display name
session.setAttribute("email", member.getEmail());   // Email

3. Route Protection

// Redirect to login if not authenticated
if (session.getAttribute("userId") == null) {
    return "redirect:/member_login";
}

4. Server-Side Data Binding

// Author assigned from session (prevents client manipulation)
String userName = (String) session.getAttribute("userName");
request.setUser(userName);  // Not from form input

πŸ“ How to Use

1️⃣ Register Account

  1. Go to http://localhost:8080/join_new
  2. Fill in: Name, Email, Password, Age, Mobile, Address
  3. Submit β†’ Password encrypted with BCrypt
  4. Success page displayed

2️⃣ Login

  1. Go to http://localhost:8080/member_login
  2. Enter email and password
  3. Session created (UUID + user info)
  4. Redirected to board list

3️⃣ Create Post

  1. Click "κΈ€μ“°κΈ°" (Write) button
  2. Login required (auto-redirect if not logged in)
  3. Fill form:
    • Title (max 200 chars) βœ… Required
    • Password (for post security)
    • Content (max 5000 chars) βœ… Required
  4. Author auto-set from session
  5. Date auto-set (dd-MM-yyyy)
  6. Submit β†’ Validated & saved

4️⃣ Search Posts

  • Enter keyword β†’ Searches titles (case-insensitive)
  • Clear search β†’ Shows all posts

5️⃣ Navigate Pages

  • 3 posts per page
  • Use numbered pagination links
  • Previous/Next buttons

6️⃣ Logout

  • Click "λ‘œκ·Έμ•„μ›ƒ" button
  • Session cleared
  • Redirected to login

πŸ”§ Configuration

Database (application.properties)

spring.datasource.url=jdbc:mysql://localhost:3306/spring?serverTimezone=Asia/Seoul
spring.datasource.username=root
spring.datasource.password=123123  # Change this
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

Session Settings

server.servlet.session.timeout=300s           # 5 minutes
server.servlet.session.cookie.secure=true     # HTTPS only

File Upload

spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=30MB
spring.servlet.multipart.location=./src/main/resources/static/upload

πŸ§ͺ Testing Checklist

Authentication

  • βœ… Register β†’ Password encrypted in DB
  • βœ… Login success β†’ Session created
  • βœ… Login fail β†’ Error message
  • βœ… Duplicate email β†’ Prevented
  • βœ… Logout β†’ Session cleared

Board System

  • βœ… Create post β†’ Author from session
  • βœ… Validation β†’ Empty title rejected
  • βœ… Date format β†’ dd-MM-yyyy
  • βœ… Search β†’ Case-insensitive
  • βœ… Pagination β†’ Works correctly

Security

  • βœ… Protected route β†’ Redirects to login
  • βœ… Multi-user β†’ Independent sessions
  • βœ… Session timeout β†’ Works as configured

πŸ› Troubleshooting

App Won't Start

MySQL connection error:

  • βœ… MySQL running: mysql -u root -p
  • βœ… Database exists: CREATE DATABASE spring;
  • βœ… Credentials correct in application.properties

Port 8080 in use:

# Windows: Kill process
netstat -ano | findstr :8080
taskkill /PID <pid> /F

# Or change port
server.port=8081

Login Issues

Correct credentials but login fails:

  • βœ… Check PasswordEncoder bean configured
  • βœ… Verify user in DB: SELECT * FROM member WHERE email='test@test.com';
  • βœ… Password should start with $2a$ or $2b$

Session lost immediately:

  • βœ… Enable cookies in browser
  • βœ… If HTTP (not HTTPS): server.servlet.session.cookie.secure=false

Board Errors

500 Error creating post:

  • βœ… Session has userName: Check login sets it
  • βœ… All NOT NULL fields have values
  • βœ… Validation passes (title/content not blank)

Author shows UUID:

  • βœ… Fixed: Now uses userName from session
  • βœ… Check board_write.html: th:value="${userName}"

πŸ“š Key Learnings

This project demonstrates:

  • βœ… Spring Boot 3.5.8 - Auto-configuration, starters
  • βœ… Spring MVC - Controllers, request mapping
  • βœ… Spring Data JPA - Repositories, entities, queries
  • βœ… Spring Security - BCrypt, authentication
  • βœ… Thymeleaf - Server-side templates
  • βœ… MySQL & Hibernate - ORM, database management
  • βœ… Session Management - Multi-user support with UUID
  • βœ… Input Validation - Bean Validation API
  • βœ… Layered Architecture - Controller β†’ Service β†’ Repository
  • βœ… DTO Pattern - Clean data transfer
  • βœ… Security Best Practices - Password hashing, session security

πŸ”„ Future Enhancements

Planned Features

  • Edit/delete posts with password verification
  • View counter increment
  • Like/unlike functionality
  • Comment system
  • User profile pages
  • Post categories
  • Rich text editor (Markdown)
  • Email verification
  • Password reset

Technical Upgrades

  • Unit & integration tests (JUnit 5)
  • REST API with JWT
  • Role-based access control
  • Database migrations (Flyway)
  • Redis session store
  • Caching layer
  • Docker containerization
  • CI/CD pipeline

References


About

SKU Class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published