技术范围: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 {@Autowiredprivate 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());}}
}