当前位置: 首页 > article >正文

基于javaweb的SpringBoot商品进销存系统设计和实现(源码+文档+部署讲解)

技术范围:SpringBoot、Vue、SSM、HLMT、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、小程序、安卓app、大数据、物联网、机器学习等设计与开发。

主要内容:免费功能设计、开题报告、任务书、中期检查PPT、系统功能实现、代码编写、论文编写和辅导、论文降重、长期答辩答疑辅导、腾讯会议一对一专业讲解辅导答辩、模拟答辩演练、和理解代码逻辑思路。

🍅文末获取源码联系🍅
🍅文末获取源码联系🍅
🍅文末获取源码联系🍅

👇🏻 精彩专栏推荐订阅👇🏻 不然下次找不到哟

《课程设计专栏》
《Java专栏》
《Python专栏》
⛺️心若有所向往,何惧道阻且长

文章目录

    • 技术架构概览
    • 适用
    • 界面展示
    • 接口返回数据格式
    • 用户信息控制器

在当今数字化时代,高效的商品进销存管理系统对于企业运营至关重要。本文将深入介绍基于 JavaWeb 的 Spring Boot 商品进销存系统,涵盖其技术架构、核心代码实现以及关键功能模块。

技术架构概览

本系统采用了一系列先进的技术,构建了一个稳定、高效且易于维护的架构。核心技术栈包括:
后端:Spring + Spring Boot + MyBatis + Maven
前端:Vue
数据库:MySQL
开发工具:Jdk1.8、Mysql、HBuilderX(或 Webstorm)、Eclispe(或 IntelliJ IDEA、MyEclispe、Sts)

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

界面展示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

接口返回数据格式

系统定义了统一的接口返回数据格式,确保数据传输的一致性和可理解性。

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel(value = "接口返回对象", description = "接口返回对象")
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "成功标志")
    private boolean success = true;

    @ApiModelProperty(value = "返回处理消息")
    private String message = "操作成功!";

    @ApiModelProperty(value = "返回代码")
    private Integer code = 0;

    @ApiModelProperty(value = "返回数据对象 data")
    private T result;

    @ApiModelProperty(value = "时间戳")
    private long timestamp = System.currentTimeMillis();

    public Result() {}

    public Result success(String message) {
        this.message = message;
        this.code = CommonConstant.SC_OK_200;
        this.success = true;
        return this;
    }

    public static Result ok() {
        Result r = new Result();
        r.setSuccess(true);
        r.setCode(CommonConstant.SC_OK_200);
        r.setMessage("成功");
        return r;
    }

    public static Result ok(String msg) {
        Result r = new Result();
        r.setSuccess(true);
        r.setCode(CommonConstant.SC_OK_200);
        r.setMessage(msg);
        return r;
    }

    public static Result ok(Object data) {
        Result r = new Result();
        r.setSuccess(true);
        r.setCode(CommonConstant.SC_OK_200);
        r.setResult(data);
        return r;
    }

    public static Result error(String msg) {
        return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
    }

    public static Result error(int code, String msg) {
        Result r = new Result();
        r.setCode(code);
        r.setMessage(msg);
        r.setSuccess(false);
        return r;
    }

    public Result error500(String message) {
        this.message = message;
        this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
        this.success = false;
        return this;
    }

    public static Result noauth(String msg) {
        return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg);
    }
}

用户信息控制器

用户信息控制器负责处理与用户相关的请求,如权限验证、文件上传等。

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileCopyUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/sys/common")
public class CommonController {

    @Autowired
    private ISysBaseAPI sysBaseAPI;

    @Value(value = "${jeecg.path.upload}")
    private String uploadpath;

    @Value(value = "${jeecg.uploadType}")
    private String uploadType;

    @GetMapping("/403")
    public Result<?> noauth() {
        return Result.error("没有权限,请联系管理员授权");
    }

    @PostMapping(value = "/upload")
    public Result<?> upload(HttpServletRequest request, HttpServletResponse response) {
        Result<?> result = new Result<>();
        String savePath = "";
        String bizPath = request.getParameter("biz");

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile("file");

        if (StringUtils.isEmpty(bizPath)) {
            if (CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)) {
                bizPath = "upload";
            } else {
                bizPath = "";
            }
        }

        if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
            String jeditor = request.getParameter("jeditor");
            if (StringUtils.isNotEmpty(jeditor)) {
                result.setMessage(CommonConstant.UPLOAD_TYPE_LOCAL);
                result.setSuccess(true);
                return result;
            } else {
                savePath = this.uploadLocal(file, bizPath);
            }
        } else {
            savePath = sysBaseAPI.upload(file, bizPath, uploadType);
        }

        if (StringUtils.isNotEmpty(savePath)) {
            result.setMessage(savePath);
            result.setSuccess(true);
        } else {
            result.setMessage("上传失败!");
            result.setSuccess(false);
        }

        return result;
    }

    private String uploadLocal(MultipartFile mf, String bizPath) {
        try {
            String ctxPath = uploadpath;
            String fileName = null;

            File file = new File(ctxPath + File.separator + bizPath + File.separator);
            if (!file.exists()) {
                file.mkdirs();
            }

            String orgName = mf.getOriginalFilename();
            orgName = CommonUtils.getFileName(orgName);

            if (orgName.indexOf(".")!= -1) {
                fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
            } else {
                fileName = orgName + "_" + System.currentTimeMillis();
            }

            String savePath = file.getPath() + File.separator + fileName;
            File savefile = new File(savePath);
            FileCopyUtils.copy(mf.getBytes(), savefile);

            String dbpath = null;
            if (StringUtils.isNotEmpty(bizPath)) {
                dbpath = bizPath + File.separator + fileName;
            } else {
                dbpath = fileName;
            }

            if (dbpath.contains("\\")) {
                dbpath = dbpath.replace("\\", "/");
            }

            return dbpath;
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            return "";
        }
    }

    @GetMapping(value = "/static/**")
    public void view(HttpServletRequest request, HttpServletResponse response) {
        String imgPath = extractPathFromPattern(request);
        if (StringUtils.isEmpty(imgPath) || "null".equals(imgPath)) {
            return;
        }

        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            imgPath = imgPath.replace("..", "");
            if (imgPath.endsWith(",")) {
                imgPath = imgPath.substring(0, imgPath.length() - 1);
            }

            String filePath = uploadpath + File.separator + imgPath;
            File file = new File(filePath);
            if (!file.exists()) {
                response.setStatus(HttpStatus.NOT_FOUND.value());
                throw new RuntimeException("文件不存在..");
            }

            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
            response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"), "iso-8859-1"));

            inputStream = new BufferedInputStream(new FileInputStream(filePath));
            outputStream = response.getOutputStream();

            byte[] buf = new byte[1024];
            int len;
            while ((len = inputStream.read(buf)) > 0) {
                outputStream.write(buf, 0, len);
            }
            response.flushBuffer();
        } catch (IOException e) {
            log.error("预览文件失败" + e.getMessage());
            response.setStatus(HttpStatus.NOT_FOUND.value());
            e.printStackTrace();
        } finally {
            if (inputStream!= null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(), e);
                }
            }
            if (outputStream!= null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
    }

    @RequestMapping("/pdf/pdfPreviewIframe")
    public ModelAndView pdfPreviewIframe(ModelAndView modelAndView) {
        modelAndView.setViewName("pdfPreviewIframe");
        return modelAndView;
    }

    private static String extractPathFromPattern(final HttpServletRequest request) {
        String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
        return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path);
    }

    @RequestMapping("/transitRESTful")
    public Result transitRESTful(@RequestParam("url") String url, HttpServletRequest request) {
        try {
            ServletServerHttpRequest httpRequest = new ServletServerHttpRequest(request);
            HttpMethod method = httpRequest.getMethod();

            JSONObject params;
            try {
                params = JSON.parseObject(JSON.toJSONString(httpRequest.getBody()));
            } catch (Exception e) {
                params = new JSONObject();
            }

            JSONObject variables = JSON.parseObject(JSON.toJSONString(request.getParameterMap()));
            variables.remove("url");

            String token = TokenUtils.getTokenByRequest(request);
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Access-Token", token);

            String httpURL = URLDecoder.decode(url, "UTF-8");
            ResponseEntity response = RestUtil.request(httpURL, method, headers, variables, params, String.class);

            Result result = new Result<>();
            int statusCode = response.getStatusCodeValue();
            result.setCode(statusCode);
            result.setSuccess(statusCode == 200);

            String responseBody = response.getBody();
            try {
                Object json = JSON.parse(responseBody);
                result.setResult(json);
            } catch (Exception e) {
                result.setResult(responseBody);
            }

            return result;
        } catch (Exception e) {
            log.debug("中转HTTP请求失败", e);
            return Result.error(e.getMessage());
        }
    }
}

http://www.kler.cn/a/554682.html

相关文章:

  • SQL FIRST() 函数详解
  • 强化学习入门
  • MySQL 三层 B+ 树能存多少数据?
  • Maven 与 Kubernetes 部署:构建和部署到 Kubernetes 环境中
  • Windows环境打印文档的同时自动生成PDF副本的方法
  • ffmpeg 多路流处理在iOS的具体使用
  • 2024年国赛高教杯数学建模A题板凳龙闹元宵解题全过程文档及程序
  • 悬挂引用,智能指针 裸指针 悬挂指针
  • 基础前端面试题:HTML网站开发中,如何实现图片的懒加载
  • rust笔记7-生命周期显式标注
  • 3分钟了解内外网文件传输:常见方法、注意事项有哪些?
  • 13-R数据重塑
  • 后端Java Stream数据流的使用=>代替for循环
  • Compose 组件渲染流程
  • 如何在Ubuntu 22.04上安装NVIDIA驱动:自动安装与手动安装的全面指南
  • 非常简洁的一个 Excel 导出封装,生成多个 Excel 文件并打包成 zip 通过浏览器下载
  • 责任链模式原理详解和源码实例以及Spring AOP拦截器链的执行源码如何使用责任链模式?
  • UEFI Spec 学习笔记---6 - Block Translation Table (BTT) Layout
  • 算法从0到100之【专题一】- 双指针第一练(数组划分、数组分块)
  • AI 是如何赋能企业,推动新的“商业革命”的?