Building a Second-Hand Commerce Platform with Spring Boot and MySQL

The application follows a decoupled B/S architecture, leveraging Spring Boot for RESTful API provisioning and MySQL for relational data persistence. Entity-Relationship modeling adheres to third normal form, utilizing UTF-8 collation for consistent string handling across international deployments.

Database Schema Design

Core tables manage administrative access, product catalogs, and promotional assets. Indexing strategies optimize query performance for high-frequency searches.

CREATE TABLE `sys_admin_auth`
(
    `admin_id`         BIGINT AUTO_INCREMENT PRIMARY KEY,
    `login_identifier` VARCHAR(50)  NOT NULL UNIQUE,
    `credential_hash`  VARCHAR(128) NOT NULL,
    `display_alias`    VARCHAR(50)  NOT NULL,
    `account_status`   TINYINT(1)   DEFAULT 0 COMMENT '0=active, 1=suspended'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `commerce_products`
(
    `item_id`       BIGINT AUTO_INCREMENT PRIMARY KEY,
    `owner_id`      BIGINT       NOT NULL,
    `category_path` VARCHAR(100) NOT NULL,
    `listing_title` VARCHAR(150) NOT NULL,
    `asked_price`   DECIMAL(10,2) NOT NULL,
    `publish_state` TINYINT(1)   DEFAULT 1 COMMENT '1=visible, 0=hidden'
);

Authentication Module

Client interfaces transmit credentials through secured POST endpoints. Captcha verification mitigates automated brute-force attempts before database queries are executed.

<form id="loginForm" action="/api/auth/verify" method="POST">
  <div class="field-wrapper">
    <label for="userId">Registered Phone / Email</label>
    <input type="text" id="userId" name="identifier" required autocomplete="username" />
  </div>
  <div class="field-wrapper">
    <label for="userPass">Password</label>
    <input type="password" id="userPass" name="credential" required autocomplete="current-password" />
  </div>
  <div class="field-wrapper">
    <label for="securityCode">Captcha</label>
    <input type="text" id="securityCode" name="captcha" required maxlength="6" />
    <img src="/api/security/gen" alt="Refresh code" onclick="refreshCaptcha()" />
  </div>
  <button type="submit">Proceed</button>
</form>

Server-side controllers parse incoming payloads, validate security tokens, and initialize protected session contexts up on successful authentication.

@RestController
@RequestMapping("/api/v1/session")
public class AuthenticationHandler {

    private final IdentityValidator userVerifier;
    private final TokenService captchaChecker;

    @PostMapping("/authenticate")
    public ResponseEntity<AuthResponse> processLogin(
            @RequestParam("identifier") String userHandle,
            @RequestParam("credential") String secretKey,
            @RequestParam("captcha") String codeInput,
            HttpServletRequest httpRequest) {

        if (StringUtils.isEmpty(codeInput)) {
            return ResponseEntity.badRequest().body(new AuthResponse(Map.of("error", "Missing security token")));
        }

        String expectedToken = (String) httpRequest.getSession().getAttribute("captcha_payload");
        if (!codeInput.equals(expectedToken)) {
            return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
                                 .body(new AuthResponse(Map.of("error", "Captcha mismatch")));
        }

        UserProfile validatedUser = userVerifier.validateCredentials(userHandle, secretKey);
        if (validatedUser == null) {
            return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
                                 .body(new AuthResponse(Map.of("error", "Invalid credentials")));
        }

        HttpSession session = httpRequest.getSession(true);
        session.setAttribute("current_operator", validatedUser.getAlias());
        session.setAttribute("operator_uid", validatedUser.getId());
        session.setMaxInactiveInterval(7200);

        return ResponseEntity.ok(new AuthResponse(Map.of("status", "success", "next_page", "/dashboard")));
    }
}

Inventory and Category Administration

Administrative dashboards expose endpoints for managing product lifecycles. Bulk operations allow suppliers to update pricing tiers, toggle visibility flags, and reassign category hierarchies. Dynamic banner configuration routes media files to frontend rotators based on priority weights and scheduled publication windows.

Transaction and Order Processing

Customer workflows consolidate selected items in to temporary cart stores synchronized with localStorage or server-side sessions. Checkout routines validate inventory availability, calculate tax adjustments, and generate immutable order records. Purchase history filters retrieve past transactions alongside shipping manifests and invoice attachments.

Payment gateway callbacks reconcile ledger states, transitioning order statuses from panding to fulfilled. Automated notifications dispatch confirmation emails containing tracking identifiers and estimated delivery timelines.

Tags: java Spring Boot MySQL E-commerce web development

Posted on Tue, 08 Sep 2026 16:19:51 +0000 by bob2006