赞
踩
采用SSM框架技术,其中涉及模块,根据网上一些博客因个人项目而整理开发,可作为他人开发参考
本人开发参考:https://zoutao.blog.csdn.net/article/details/81747046
本地目录文件,Linux环境可更换配置
#临时的视频存储路径,转码完成后删除
TEMPORARY_VIDEO_PATH=D:/zhongjianjian/temp/
#转码成功mp4视频存放路径
TRANSCODE_VIDEO_MP4PATH=D:/zhongjianjian/finshvideo/
#转码ffmpeg.exe工具路径
FFMPEG_PATH=D:/zhongjianjian/tools/ffmpeg.exe
#转码mencoder.exe工具路径
MENCODER_PATH=D:/zhongjianjian/tools/mencoder.exe
#视频截图存放路径
filePath=D:/zhongjianjian/views/static/
ResourceService.java 方便用于加载配置文件 serviceconfig.properties 中的变量
package com.sslt.utils; import java.util.Enumeration; import java.util.ResourceBundle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 加载静态资源服务 * @author * */ public class ResourceService { private final static Logger logger = LoggerFactory.getLogger(ResourceService.class); /** 参数配置文件 */ public static ResourceBundle rb = null; /** * 项目启动系统所需配置文件,仅此一次 */ static{ rb = ResourceBundle.getBundle("serviceconfig"); } public static void refresh() { logger.info("开始重载serviceconfig配置文件......"); ResourceBundle.clearCache(); rb = ResourceBundle.getBundle("serviceconfig"); logger.info("检查serviceconfig文件是否重载完成......"); Enumeration<String> keys = rb.getKeys(); while(keys.hasMoreElements()){ String key = keys.nextElement(); String value = rb.getString(key); logger.info("serviceconfig配制已经重载--> "+key + " : " + value); } logger.info("serviceconfig配制文件重载完成!"); } }
ResultBean.java 作为统一响应数据格式
package com.sslt.common; /** * 自定义响应结构 */ public class ResultBean { // 响应业务状态 private Integer status; // 响应消息 private String msg; // 响应中的数据 private Object data; public static ResultBean build(Integer status, String msg, Object data) { return new ResultBean(status, msg, data); } public static ResultBean success(Object data) { return new ResultBean(data); } public static ResultBean success() { return new ResultBean(null); } public ResultBean() { } public static ResultBean build(Integer status, String msg) { return new ResultBean(status, msg, null); } public ResultBean(Integer status, String msg, Object data) { this.status = status; this.msg = msg; this.data = data; } public ResultBean(Object data) { this.status = 200; this.msg = "SUCCESS"; this.data = data; } public Integer getStatus() { return status; } public void setStatus(Integer status) { this.status = status; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public Object getData() { return data; } public void setData(Object data) { this.data = data; } }
响应码工具类 GlobalState.java,可配置统一静态变量
package com.sslt.common; /** * 静态变量工具类 * @author MINI * */ public class GlobalState { public static final Integer RESULTSTATUS = 200; // 默认返回成功状态码 public static final Integer FAILSTATUS = 401; // 失败状态 public static final Integer PASTSTATUS = 400; // 过期状态 }
FileUploadToolUtil.java 检测文件类型包括图片和视频格式,检测文件格式是否支持、大小和不能为空
package com.sslt.utils; import java.io.File; import java.text.DecimalFormat; import java.util.Arrays; import java.util.Iterator; import javax.servlet.http.HttpServletRequest; import org.springframework.web.multipart.MultipartFile; import com.sslt.common.GlobalState; import com.sslt.common.ResultBean; /** * 文件校验 * @author MINI * */ public class FileUploadToolUtil { // 文件最大500M private static long upload_maxsize = 500 * 1024 * 1024; // 文件允许格式 private static String[] allowFiles = { ".rar", ".doc", ".docx", ".zip", ".pdf", ".txt", ".swf", ".xlsx", ".gif", ".png", ".jpg", ".jpeg", ".bmp", ".xls", ".mp4", ".flv", ".ppt", ".avi", ".mpg", ".wmv", ".3gp", ".mov", ".asf", ".asx", ".vob", ".wmv9", ".rm", ".rmvb" }; public static ResultBean createFile(MultipartFile multipartFile, HttpServletRequest request) { Integer status = GlobalState.RESULTSTATUS; String msg = ""; String fileName = multipartFile.getOriginalFilename().toString(); // 判断文件不为空 if (multipartFile.getSize() != 0 && !multipartFile.isEmpty()) { // 判断文件大小 if (multipartFile.getSize() <= upload_maxsize) { // 文件类型判断 if (!checkFileType(fileName)) { status = GlobalState.FAILSTATUS; msg = fileName + "文件,系统暂不支持" + fileName.substring(fileName.lastIndexOf("."),fileName.length()) + "的文件格式!"; } } else { status = GlobalState.FAILSTATUS; msg = "文件大小超范围"; } } else { status = GlobalState.FAILSTATUS; msg = "上传文件不能为空"; } return ResultBean.build(status, msg); } /** * 文件类型判断 * * @param fileName * @return */ public static boolean checkFileType(String fileName) { Iterator<String> type = Arrays.asList(allowFiles).iterator(); while (type.hasNext()) { String ext = type.next(); if (fileName.toLowerCase().endsWith(ext)) { return true; } } return false; } /** * 获取文件扩展名 * * @return string */ public static String getFileExt(String fileName) { return fileName.substring(fileName.lastIndexOf(".")); } /** * 依据原始文件名生成新文件名 * @return */ public static String getName(String fileName) { Iterator<String> type = Arrays.asList(allowFiles).iterator(); while (type.hasNext()) { String ext = type.next(); if (fileName.contains(ext)) { String newFileName = fileName.substring(0, fileName.lastIndexOf(ext)); return newFileName; } } return ""; } /** * 文件大小,返回kb.mb * * @return */ public static String getSize(File file) { String size = ""; long fileLength = file.length(); DecimalFormat df = new DecimalFormat("#.00"); if (fileLength < 1024) { size = df.format((double) fileLength) + "BT"; } else if (fileLength < 1048576) { size = df.format((double) fileLength / 1024) + "KB"; } else if (fileLength < 1073741824) { size = df.format((double) fileLength / 1048576) + "MB"; } else { size = df.format((double) fileLength / 1073741824) + "GB"; } return size; } }
DisposeVideoUtils.java 处理视频写入本地磁盘/服务器,将非MP4格式的格式文件进行转码写入处理,并且写入前进行视频截图
package com.sslt.utils;
import java.io.BufferedReader;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。