Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Implementing a Pet Store Management System with SSM Framework

Tech 1

System Overview

A pet store management system built with SSM (Spring, Spring MVC, MyBatis) supports three user roles: administrator, customer, and trainer.

  • Administrator: Manages pets, pet food, supplies, vaccine appointments, grooming services, training schedules, and orders.
  • Customer: Registers, logs in, uses shopping cart, places orders, purchases pets, books training and grooming appointments, and schedules vaccinations.
  • Trainer: Logs in, registers, and manages pet training sessions.

Technical Stack

  • Backend: SSM framework (Spring for dependency injection and lifecycle management, Spring MVC for request handling, MyBatis for database operations).
  • Frontend: Bootstrap and JSP for user interface.
  • Database: MySQL (versions 5.7 or 8.x), chosen for its lightweight nature, open-source availability, and cost-effectiveness in development environments.

Development Environment

  • Java: JDK 1.8 recommended.
  • IDE: Compatible with IntelliJ IDEA or Eclipse.
  • Server: Apache Tomcat (versions 7 to 10).
  • Build Tool: Maven (any version).
  • Operating System: Windows.

Core Implemantation

Data base Configuration

validationQuery=SELECT 1
jdbc_url=jdbc:mysql://localhost:3306/petstore_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
jdbc_username=admin
jdbc_password=admin123

User Authentication Controller

package com.petstore.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.petstore.entity.Account;
import com.petstore.service.AccountService;
import com.petstore.service.AuthTokenService;
import com.petstore.util.ResponseResult;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/accounts")
public class AccountController {
    @Autowired
    private AccountService accountService;
    @Autowired
    private AuthTokenService tokenService;

    @PostMapping("/authenticate")
    public ResponseResult login(@RequestParam String username, @RequestParam String password) {
        Account account = accountService.findByUsername(username);
        if (account == null || !account.getPassword().equals(password)) {
            return ResponseResult.error("Invalid credentials");
        }
        String token = tokenService.createToken(account.getId(), username, account.getRole());
        return ResponseResult.success().addData("token", token);
    }

    @PostMapping("/register")
    public ResponseResult signUp(@RequestBody Account newAccount) {
        if (accountService.findByUsername(newAccount.getUsername()) != null) {
            return ResponseResult.error("Username already exists");
        }
        accountService.saveAccount(newAccount);
        return ResponseResult.success();
    }

    @GetMapping("/logout")
    public ResponseResult logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return ResponseResult.success("Logged out");
    }

    @PostMapping("/reset-password")
    public ResponseResult resetPassword(@RequestParam String username) {
        Account account = accountService.findByUsername(username);
        if (account == null) {
            return ResponseResult.error("Account not found");
        }
        account.setPassword("default123");
        accountService.updateAccount(account);
        return ResponseResult.success("Password reset to default123");
    }

    @GetMapping
    public ResponseResult getAllAccounts() {
        List<Account> accounts = accountService.listAll();
        return ResponseResult.success().addData("accounts", accounts);
    }
}

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.