Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Development and Implementation of a Conventional Emergency Supplies Management System Using Spring Boot and Vue.js

Tech 1

In the current digital age, many industries are transitioning to digital and informatized operations by integrating computer technology. Traditional manual registration and management of conventional emergency supplies data are inefficient and outdated. This system, built on B/S architecture with Spring Boot backend and Vue.js frontend, reduces resource waste and enables timely data updates and storage. It leverages IntelliJ IDEA for Java coding, MySQL for database design, SSM as the core framework, and Tomcat for web deployment.

Development Environment

  • Programming Language: Java
  • Backend Framework: Spring Boot
  • JDK Version: JDK 1.8
  • Web Server: Tomcat 7
  • Database: MySQL 5.7
  • Data base Tool: Navicat 11
  • IDE: IntelliJ IDEA / Eclipse / MyEclipse
  • Build Tool: Maven 3.3.9
  • Browser: Google Chrome
  • Backend Access URL: localhost:8080/{projectName}/admin/dist/index.html
  • Frontend Access URL: localhost:8080/{projectName}/front/dist/index.html (omit if no frontend)
  • Admin Account: admin / admin

Core Technologies Overview

Java is a statically typed, object-oriented programming language known for multi-threading, robustness, and platform independence. It supports encapsulation, inheritance, and polymorphism to enhance code reusability and modularity, with built-in garbage collection and exception handling mechanisms. Its network interfaces and extensive standard libraries simplify web and enterprise application development.

Spring Boot simplifies Spring application setup by eliminating verbose configuration and integrating a wide range of compatible third-party libraries, resolving dependency conflicts and boosting development efficiency.

MySQL is a lightweight, high-performance relational database management system from Oracle. It features a simple SQL syntax, fast query execution, and strong security, making it ideal for web application data storage and management.

Core Code Examples

package com.example.controller;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.example.annotation.PublicEndpoint;
import com.example.entity.SystemConfig;
import com.example.exception.BusinessException;
import com.example.service.SystemConfigService;
import com.example.vo.ApiResponse;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.UUID;

@RestController
@RequestMapping("/api/files")
public class FileController {
    @Autowired
    private SystemConfigService systemConfigService;

    @PostMapping("/upload")
    @PublicEndpoint
    public ApiResponse<String> uploadFile(@RequestParam("file") MultipartFile file, @RequestParam(required = false) String configKey) {
        if (file.isEmpty()) {
            throw new BusinessException("Uploaded file cannot be empty");
        }
        String originalFileName = file.getOriginalFilename();
        String fileExtension = originalFileName.substring(originalFileName.lastIndexOf(".") + 1).toLowerCase();
        File resourcePath;
        try {
            resourcePath = new File(ResourceUtils.getURL("classpath:static").getPath());
            if (!resourcePath.exists()) {
                resourcePath = new File(".");
            }
        } catch (Exception e) {
            throw new BusinessException("Failed to locate resource directory");
        }
        File uploadDir = new File(resourcePath.getAbsolutePath(), "uploads");
        if (!uploadDir.exists()) {
            boolean created = uploadDir.mkdirs();
            if (!created) {
                throw new BusinessException("Failed to create upload directory");
            }
        }
        String savedFileName = UUID.randomUUID().toString().replace("-", "") + "." + fileExtension;
        File destFile = new File(uploadDir, savedFileName);
        try {
            file.transferTo(destFile);
            // Uncomment below to copy files to local static directory for IDE hot reload (replace path with your local one)
            // FileUtils.copyFile(destFile, new File("C:\\Projects\\emergency-supplies\\src\\main\\resources\\static\\uploads\\" + savedFileName));
        } catch (IOException e) {
            throw new BusinessException("File transfer failed: " + e.getMessage());
        }
        if (StringUtils.isNotBlank(configKey)) {
            SystemConfig config = systemConfigService.findByKey(configKey);
            if (config == null) {
                config = new SystemConfig();
                config.setConfigKey(configKey);
                config.setConfigValue(savedFileName);
            } else {
                config.setConfigValue(savedFileName);
            }
            systemConfigService.saveOrUpdate(config);
        }
        return ApiResponse.success(savedFileName);
    }

    @GetMapping("/download")
    @PublicEndpoint
    public ResponseEntity<byte[]> downloadFile(@RequestParam String fileName) {
        try {
            File resourcePath = new File(ResourceUtils.getURL("classpath:static").getPath());
            if (!resourcePath.exists()) {
                resourcePath = new File(".");
            }
            File uploadDir = new File(resourcePath.getAbsolutePath(), "uploads");
            File targetFile = new File(uploadDir, fileName);
            if (!targetFile.exists()) {
                return new ResponseEntity<>(HttpStatus.NOT_FOUND);
            }
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
            headers.setContentDispositionFormData("attachment", fileName);
            return new ResponseEntity<>(FileUtils.readFileToByteArray(targetFile), headers, HttpStatus.OK);
        } catch (Exception e) {
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}
package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.annotation.PublicEndpoint;
import com.example.entity.CommunityForum;
import com.example.service.CommunityForumService;
import com.example.vo.ApiResponse;
import com.example.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/community-forum")
public class CommunityForumController {
    @Autowired
    private CommunityForumService forumService;

    @GetMapping("/admin/list")
    public ApiResponse<PageResult<CommunityForum>> adminList(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            CommunityForum condition,
            HttpServletRequest request) {
        Page<CommunityForum> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<CommunityForum> queryWrapper = new LambdaQueryWrapper<>();
        if (!"admin".equals(request.getSession().getAttribute("role"))) {
            queryWrapper.eq(CommunityForum::getCreatedBy, request.getSession().getAttribute("userId"));
        }
        IPage<CommunityForum> result = forumService.page(page, queryWrapper);
        return ApiResponse.success(new PageResult<>(result.getRecords(), result.getTotal()));
    }

    @PublicEndpoint
    @GetMapping("/public/list")
    public ApiResponse<PageResult<CommunityForum>> publicList(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            CommunityForum condition) {
        Page<CommunityForum> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<CommunityForum> queryWrapper = new LambdaQueryWrapper<>();
        IPage<CommunityForum> result = forumService.page(page, queryWrapper);
        return ApiResponse.success(new PageResult<>(result.getRecords(), result.getTotal()));
    }

    @PublicEndpoint
    @GetMapping("/public/detail/{id}")
    public ApiResponse<CommunityForum> getDetail(@PathVariable Long id) {
        CommunityForum forum = forumService.getById(id);
        if (forum == null) {
            return ApiResponse.error("Forum not found");
        }
        return ApiResponse.success(forum);
    }

    @PublicEndpoint
    @GetMapping("/public/thread/{id}")
    public ApiResponse<CommunityForum> getThread(@PathVariable Long id) {
        CommunityForum forum = forumService.getById(id);
        if (forum == null) {
            return ApiResponse.error("Forum thread not found");
        }
        loadReplies(forum);
        return ApiResponse.success(forum);
    }

    private void loadReplies(CommunityForum forum) {
        List<CommunityForum> replies = forumService.list(new LambdaQueryWrapper<CommunityForum>().eq(CommunityForum::getParentId, forum.getId()));
        if (replies == null || replies.isEmpty()) {
            return;
        }
        forum.setReplies(replies);
        for (CommunityForum reply : replies) {
            loadReplies(reply);
        }
    }

    @PostMapping("/save")
    public ApiResponse<Void> save(@RequestBody CommunityForum forum, HttpServletRequest request) {
        forum.setId(new Date().getTime() + (long) (Math.random() * 1000));
        forum.setCreatedBy((Long) request.getSession().getAttribute("userId"));
        forum.setCreatedAt(new Date());
        forumService.save(forum);
        return ApiResponse.success();
    }

    @PutMapping("/update")
    public ApiResponse<Void> update(@RequestBody CommunityForum forum) {
        forum.setUpdatedAt(new Date());
        forumService.updateById(forum);
        return ApiResponse.success();
    }

    @DeleteMapping("/delete")
    public ApiResponse<Void> delete(@RequestBody List<Long> ids) {
        forumService.removeByIds(ids);
        return ApiResponse.success();
    }
}

System Functionality Testing

The system was first installed and tested on a local server. Based on a thorough understanding of its structure, logic, and features, both white-box and black-box testing were performed. Software testing aims to identify existing errors and prevent potential ones. Testing was guided by principles such as traceability to user requirements, early planning before coding, focusing on high-risk modules (80% of errors typically occur in 20% of modules), and incremental testing from single functions to full integration. Careful test case design ensured comprehensive coverage of program logic and requirements.

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.