SpringBoot 实现大文件断点续传(前端基于WebUploader实现,1G文件上传只需5s)(1)

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Web前端全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024c (备注前端)
img

正文

if (StringUtils.isEmpty(msg)) {

return new ResponseResult(ResponseEnum.RESPONSE_CODE_FAIL.getMsg(), null, ResponseEnum.RESPONSE_CODE_FAIL.getCode(), CommonConst.RESPONSE_FAIL);

} else {

return new ResponseResult(msg, null, ResponseEnum.RESPONSE_CODE_FAIL.getCode(), CommonConst.RESPONSE_FAIL);

}

}

public static ResponseResult fail(int code, String msg) {

return new ResponseResult(msg, null, code, CommonConst.RESPONSE_FAIL);

}

public static ResponseResult fail(ResponseEnum responseEnum, Object obj) {

return new ResponseResult(responseEnum.getMsg(), obj, responseEnum.getCode(), 0);

}

public static ResponseResult success(Object data) {

return new ResponseResult(ResponseEnum.RESPONSE_CODE_SUCCESS.getMsg(), data, ResponseEnum.RESPONSE_CODE_SUCCESS.getCode(), CommonConst.RESPONSE_SUCCESS);

}

public static ResponseResult success(Object data, int code, String message) {

return new ResponseResult(message, data, code, CommonConst.RESPONSE_SUCCESS);

}

public ResponseResult setMessage(String message) {

this.message = message;

return this;

}

public ResponseResult setData(Object data) {

this.data = data;

return this;

}

public ResponseResult setStatus(int status) {

this.status = status;

return this;

}

public ResponseResult setCode(int code) {

this.code = code;

return this;

}

public ResponseResult setTotal(Integer total) {

this.total = total;

return this;

}

}

4、FileController代码

/**

  • @description: 文件管理-Controller

  • @author: zhangzhixiang

  • @createDate: 2019/12/9

  • @version: 1.0

*/

@RestController

@RequestMapping(“/v1.0/sys/admin/files”)

public class FileController {

private static Logger LOG = LoggerFactory.getLogger(FileController.class);

@Autowired

private IFileService fileService;

@Autowired

private IUserService userService;

/**

  • 断点叙传

  • @param file

  • @param fileMd5

  • @param chunk

  • @return com.openailab.oascloud.common.model.ResponseResult

  • @author zxzhang

  • @date 2020/1/13

*/

@PostMapping(value = “/breakpointRenewal”,

produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},

consumes = MediaType.MULTIPART_FORM_DATA_VALUE)

public ResponseResult breakpointRenewal(@RequestPart(“file”) MultipartFile file,

@RequestParam(“fileMd5”) String fileMd5,

@RequestParam(“chunk”) Integer chunk) {

try {

return fileService.breakpointRenewal(file, fileMd5, chunk);

} catch (Exception e) {

LOG.error(“FileController->breakpointRenewal throw Exception.fileMd5:{},chunk:{}”, fileMd5, chunk, e);

}

return ResponseResult.fail(null);

}

/**

  • 断点叙传注册

  • @param fileMd5

  • @param fileName

  • @param fileSize

  • @param mimetype

  • @param fileExt

  • @return com.openailab.oascloud.common.model.ResponseResult

  • @author zxzhang

  • @date 2020/1/13

*/

@PostMapping(value = “/breakpointRenewal/register”)

public ResponseResult breakpointRegister(@RequestParam(“fileMd5”) String fileMd5,

@RequestParam(“fileName”) String fileName,

@RequestParam(“fileSize”) Long fileSize,

@RequestParam(“mimetype”) String mimetype,

@RequestParam(“fileExt”) String fileExt) {

try {

return fileService.breakpointRegister(fileMd5, fileName, fileSize, mimetype, fileExt);

} catch (Exception e) {

LOG.error(“FileController->breakpointRegister throw Exception.fileMd5:{},fileName:{}”, fileMd5, fileName, e);

}

return ResponseResult.fail(null);

}

/**

  • 检查分块是否存在

  • @param fileMd5

  • @param chunk

  • @param chunkSize

  • @return com.openailab.oascloud.common.model.ResponseResult

  • @author zxzhang

  • @date 2020/1/10

*/

@PostMapping(value = “/breakpointRenewal/checkChunk”)

public ResponseResult checkChunk(@RequestParam(“fileMd5”) String fileMd5,

@RequestParam(“chunk”) Integer chunk,

@RequestParam(“chunkSize”) Integer chunkSize) {

try {

return fileService.checkChunk(fileMd5, chunk, chunkSize);

} catch (Exception e) {

LOG.error(“FileController->breakpointRenewal throw Exception.fileMd5:{},chunk:{}”, fileMd5, chunk, e);

}

return ResponseResult.fail(null);

}

/**

  • 合并文件块

  • @param fileMd5

  • @param fileName

  • @param fileSize

  • @param mimetype

  • @param fileExt

  • @return com.openailab.oascloud.common.model.ResponseResult

  • @author zxzhang

  • @date 2020/1/11

*/

@PostMapping(value = “/breakpointRenewal/mergeChunks”)

public ResponseResult mergeChunks(@RequestParam(“fileMd5”) String fileMd5,

@RequestParam(“fileName”) String fileName,

@RequestParam(“fileSize”) Long fileSize,

@RequestParam(“mimetype”) String mimetype,

@RequestParam(“fileExt”) String fileExt,

@RequestParam(“token”) String token) {

try {

LoginUserInfo user = userService.getLoginUser(token);

return fileService.mergeChunks(fileMd5, fileName, fileSize, mimetype, fileExt, user);

} catch (Exception e) {

LOG.error(“FileController->breakpointRenewal throw Exception.fileMd5:{},fileName:{}”, fileMd5, fileName, e);

}

return ResponseResult.fail(null);

}

}

5、IFileService代码

/**

  • @description: 文件管理-Interface

  • @author: zhangzhixiang

  • @createDate: 2019/12/9

  • @version: 1.0

*/

public interface IFileService {

/**

  • 断点叙传注册

  • @param fileMd5

  • @param fileName

  • @param fileSize

  • @param mimetype

  • @param fileExt

  • @return com.openailab.oascloud.common.model.ResponseResult

  • @author zxzhang

  • @date 2020/1/10

*/

ResponseResult breakpointRegister(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt);

/**

  • 断点叙传

  • @param file

  • @return com.openailab.oascloud.common.model.ResponseResult

  • @author zxzhang

  • @date 2019/12/9

*/

ResponseResult breakpointRenewal(MultipartFile file, String fileMd5, Integer chunk);

/**

  • 检查分块是否存在

  • @param fileMd5

  • @param chunk

  • @param chunkSize

  • @return com.openailab.oascloud.common.model.ResponseResult

  • @author zxzhang

  • @date 2020/1/10

*/

ResponseResult checkChunk(String fileMd5, Integer chunk, Integer chunkSize);

/**

  • 合并文件块

  • @param fileMd5

  • @param fileName

  • @param fileSize

  • @param mimetype

  • @param fileExt

  • @return com.openailab.oascloud.common.model.ResponseResult

  • @author zxzhang

  • @date 2020/1/11

*/

ResponseResult mergeChunks(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt, LoginUserInfo user);

}

6、FileServiceImpl代码

/**

  • @description: 文件管理-service

  • @author: zhangzhixiang

  • @createDate: 2019/12/9

  • @version: 1.0

*/

@Service

public class FileServiceImpl implements IFileService {

private final static Logger LOG = LoggerFactory.getLogger(FileServiceImpl.class);

private static final SimpleDateFormat format = new SimpleDateFormat(“yyyyMMdd”);

@Autowired

private FileDao fileDao;

@Autowired

private BootstrapConfig bootstrapConfig;

@Autowired

private FileManagementHelper fileManagementHelper;

@Autowired

private PageObjUtils pageObjUtils;

@Autowired

private RedisDao redisDao;

private String getUploadPath() {

return bootstrapConfig.getFileRoot() + bootstrapConfig.getUploadDir() + “/”;

}

private String getFileFolderPath(String fileMd5) {

return getUploadPath() + fileMd5.substring(0, 1) + “/” + fileMd5.substring(1, 2) + “/”;

}

private String getFilePath(String fileMd5, String fileExt) {

return getFileFolderPath(fileMd5) + fileMd5 + “.” + fileExt;

}

private String getFileRelativePath(String fileMd5, String fileExt) {

return bootstrapConfig.getUploadDir() + “/” + fileMd5.substring(0, 1) + “/” + fileMd5.substring(1, 2) + “/” + fileMd5 + “.” + fileExt;

}

private String getChunkFileFolderPath(String fileMd5) {

return bootstrapConfig.getFileRoot() + bootstrapConfig.getBreakpointDir() + “/” + fileMd5 + “/”;

}

@Override

public ResponseResult breakpointRegister(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt) {

Map<String, String> ret = Maps.newHashMap();

// 检查文件是否存在于磁盘

String fileFolderPath = this.getFileFolderPath(fileMd5);

String filePath = this.getFilePath(fileMd5, fileExt);

File file = new File(filePath);

boolean exists = file.exists();

// 检查文件是否存在于PostgreSQL中 (文件唯一标识为 fileMd5)

ResourceBO resourceBO = new ResourceBO();

resourceBO.setFileMd5(fileMd5);

resourceBO.setIsDelete(0);

List resourceBOList = fileDao.selectResourceByCondition(resourceBO);

if (exists && resourceBOList.size() > 0) {

// 既存在于磁盘又存在于数据库说明该文件存在,直接返回resId、filePath

resourceBO = resourceBOList.get(0);

ret.put(“filePath”, resourceBO.getFilePath());

ret.put(“resId”, String.valueOf(resourceBO.getResourceId()));

return ResponseResult.fail(ResponseEnum.RESPONSE_CODE_BREAKPOINT_RENEVAL_REGISTRATION_ERROR, ret);

}

//若磁盘中存在,但数据库中不存在,则生成resource记录并存入redis中

if (resourceBOList.size() == 0) {

// 首次断点叙传的文件需要创建resource新记录并返回redId,并存入redis中

resourceBO.setType(fileManagementHelper.judgeDocumentType(fileExt));

resourceBO.setStatus(TranscodingStateEnum.UPLOAD_NOT_COMPLETED.getCode());

resourceBO.setFileSize(fileSize);

resourceBO.setFileMd5(fileMd5);

resourceBO.setFileName(fileName);

resourceBO.setCreateDate(new Date());

resourceBO.setIsDelete(0);

final Integer resourceId = fileDao.addResource(resourceBO);

resourceBO.setResourceId(resourceId);

redisDao.set(RedisPrefixConst.BREAKPOINT_PREFIX + fileMd5, JSONObject.toJSONString(resourceBO), RedisPrefixConst.EXPIRE);

}

//如果redis中不存在,但数据库中存在,则存入redis中

String breakpoint = redisDao.get(RedisPrefixConst.BREAKPOINT_PREFIX + fileMd5);

if (StringUtils.isEmpty(breakpoint) && resourceBOList.size() > 0) {

resourceBO = resourceBOList.get(0);

redisDao.set(RedisPrefixConst.BREAKPOINT_PREFIX + fileMd5, JSONObject.toJSONString(resourceBO), RedisPrefixConst.EXPIRE);

}

// 若文件不存在则检查文件所在目录是否存在

File fileFolder = new File(fileFolderPath);

if (!fileFolder.exists()) {

// 不存在创建该目录 (目录就是根据前端传来的MD5值创建的)

fileFolder.mkdirs();

}

return ResponseResult.success(null);

}

@Override

public ResponseResult breakpointRenewal(MultipartFile file, String fileMd5, Integer chunk) {

Map<String, String> ret = Maps.newHashMap();

// 检查分块目录是否存在

String chunkFileFolderPath = this.getChunkFileFolderPath(fileMd5);

File chunkFileFolder = new File(chunkFileFolderPath);

if (!chunkFileFolder.exists()) {

chunkFileFolder.mkdirs();

}

// 上传文件输入流

File chunkFile = new File(chunkFileFolderPath + chunk);

try (InputStream inputStream = file.getInputStream(); FileOutputStream outputStream = new FileOutputStream(chunkFile)) {

IOUtils.copy(inputStream, outputStream);

// redis中查找是否有fileMd5的分块记录(resId)

String breakpoint = redisDao.get(RedisPrefixConst.BREAKPOINT_PREFIX + fileMd5);

ResourceBO resourceBO = new ResourceBO();

if (!StringUtils.isEmpty(breakpoint)) {

// 存在分块记录说明资源正在上传中,直接返回fileMd5对应的resId,且不再重复创建resource记录

resourceBO = JSONObject.parseObject(breakpoint, ResourceBO.class);

ret.put(“resId”, String.valueOf(resourceBO.getResourceId()));

}

} catch (IOException e) {

e.printStackTrace();

}

return ResponseResult.success(ret);

}

@Override

public ResponseResult checkChunk(String fileMd5, Integer chunk, Integer chunkSize) {

// 检查分块文件是否存在

String chunkFileFolderPath = this.getChunkFileFolderPath(fileMd5);

// 分块所在路径+分块的索引可定位具体分块

File chunkFile = new File(chunkFileFolderPath + chunk);

if (chunkFile.exists() && chunkFile.length() == chunkSize) {

return ResponseResult.success(true);

}

return ResponseResult.success(false);

}

@Override

public ResponseResult mergeChunks(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt, LoginUserInfo user) {

FileClient fileClient = ClientFactory.createClientByType(bootstrapConfig.getFileClientType());

String chunkFileFolderPath = this.getChunkFileFolderPath(fileMd5);

File chunkFileFolder = new File(chunkFileFolderPath);

File[] files = chunkFileFolder.listFiles();

final String filePath = this.getFilePath(fileMd5, fileExt);

File mergeFile = new File(filePath);

List fileList = Arrays.asList(files);

// 1. 合并分块

mergeFile = this.mergeFile(fileList, mergeFile);

if (mergeFile == null) {

return ResponseResult.fail(ResponseEnum.RESPONSE_CODE_MERGE_FILE_ERROR, null);

}

// 2、校验文件MD5是否与前端传入一致

boolean checkResult = this.checkFileMd5(mergeFile, fileMd5);

if (!checkResult) {

return ResponseResult.fail(ResponseEnum.RESPONSE_CODE_VERIFY_FILE_ERROR, null);

}

// 3、删除该文件所有分块

FileUtil.deleteDir(chunkFileFolderPath);

// 4、在redis中获取文件分块记录

String breakpoint = redisDao.get(RedisPrefixConst.BREAKPOINT_PREFIX + fileMd5);

if (StringUtils.isEmpty(breakpoint)) {

return ResponseResult.fail(“文件分块不存在”);

}

ResourceBO resourceBO = JSONObject.parseObject(breakpoint, ResourceBO.class);

// 5、删除redis分块记录

redisDao.del(RedisPrefixConst.BREAKPOINT_PREFIX + fileMd5);

// 6、组装返回结果

ret.put(“filePath”, getFileRelativePath(fileMd5, fileExt));

ret.put(“resId”, String.valueOf(resourceBO.getResourceId()));

return ResponseResult.success(ret);

}

/**

  • 合并文件

  • @param chunkFileList

  • @param mergeFile

  • @return java.io.File

  • @author zxzhang

  • @date 2020/1/11

*/

private File mergeFile(List chunkFileList, File mergeFile) {

try {

// 有删 无创建

if (mergeFile.exists()) {

mergeFile.delete();

} else {

mergeFile.createNewFile();

}

// 排序

Collections.sort(chunkFileList, (o1, o2) -> {

if (Integer.parseInt(o1.getName()) > Integer.parseInt(o2.getName())) {

return 1;

}

return -1;

});

byte[] b = new byte[1024];

RandomAccessFile writeFile = new RandomAccessFile(mergeFile, “rw”);

for (File chunkFile : chunkFileList) {

RandomAccessFile readFile = new RandomAccessFile(chunkFile, “r”);

int len = -1;

while ((len = readFile.read(b)) != -1) {

writeFile.write(b, 0, len);

}

readFile.close();

}

writeFile.close();

return mergeFile;

} catch (IOException e) {

e.printStackTrace();

return null;

}

}

/**

  • 校验文件MD5

  • @param mergeFile

  • @param md5

  • @return boolean

  • @author zxzhang

  • @date 2020/1/11

*/

private boolean checkFileMd5(File mergeFile, String md5) {

try {

// 得到文件MD5

FileInputStream inputStream = new FileInputStream(mergeFile);

String md5Hex = DigestUtils.md5Hex(inputStream);

if (StringUtils.equalsIgnoreCase(md5, md5Hex)) {

return true;

}

} catch (Exception e) {

e.printStackTrace();

}

return false;

}

/**

  • 获取文件后缀

  • @param fileName

  • @return java.lang.String

  • @author zxzhang

  • @date 2019/12/10

*/

public String getExt(String fileName) {

return fileName.substring(fileName.lastIndexOf(“.”) + 1);

}

/**

  • 获取文件所在目录

  • @param filePath

  • @return java.lang.String

  • @author zxzhang

  • @date 2019/12/10

*/

public String getFileDir(String filePath) {

return filePath.substring(0, filePath.lastIndexOf(BootstrapConst.PATH_SEPARATOR));

}

/**

  • 获取文件名

  • @param filePath

  • @return java.lang.String

  • @author zxzhang

  • @date 2019/12/10

*/

public String getFileName(String filePath) {

return filePath.substring(filePath.lastIndexOf(BootstrapConst.PATH_SEPARATOR) + 1, filePath.lastIndexOf(“.”));

}

}

7、FileUtil代码

/**

  • @description:

  • @author: zhangzhixiang

  • @createDate: 2020/1/7

  • @version: 1.0

*/

public class FileUtil {

private static final Logger LOG = LoggerFactory.getLogger(FileUtil.class);

/**

  • 清空文件夹下所有文件

  • @param path

  • @return boolean

  • @author zxzhang

  • @date 2020/1/7

*/

public static boolean deleteDir(String path) {

File file = new File(path);

if (!file.exists()) {//判断是否待删除目录是否存在

return false;

}

String[] content = file.list();//取得当前目录下所有文件和文件夹

for (String name : content) {

File temp = new File(path, name);

if (temp.isDirectory()) {//判断是否是目录

deleteDir(temp.getAbsolutePath());//递归调用,删除目录里的内容

temp.delete();//删除空目录

} else {

if (!temp.delete()) {//直接删除文件

LOG.error(“文件删除失败,file:{}” + name);

}

}

}

return true;

}

/**

  • 复制单个文件

  • @param oldPath String 原文件路径 如:c:/fqf

  • @param newPath String 复制后路径 如:f:/fqf/ff

  • @return boolean

*/

public static void copyFile(String oldPath, String newPath) {

try {

int bytesum = 0;

int byteread = 0;

File oldfile = new File(oldPath);

if (oldfile.exists()) { //文件存在时

InputStream inStream = new FileInputStream(oldPath); //读入原文件

//newFilePath文件夹不存在则创建

File newParentFile = new File(newPath).getParentFile();

if (!newParentFile.exists()) {

newParentFile.mkdirs();

}

FileOutputStream fs = new FileOutputStream(newPath);

byte[] buffer = new byte[1444];

int length;

while ((byteread = inStream.read(buffer)) != -1) {

bytesum += byteread; //字节数 文件大小

System.out.println(bytesum);

fs.write(buffer, 0, byteread);

}

inStream.close();

}

} catch (Exception e) {

LOG.error(“复制单个文件操作出错”);

e.printStackTrace();

}

}

/**

  • 复制整个文件夹内容

  • @param oldPath String 原文件路径 如:c:/fqf

  • @param newPath String 复制后路径 如:f:/fqf/ff

  • @return boolean

*/

public static void copyFolder(String oldPath, String newPath) {

try {

//newFilePath文件夹不存在则创建

File newParentFile = new File(newPath).getParentFile();

if (!newParentFile.exists()) {

newParentFile.mkdirs();

}

File a = new File(oldPath);

String[] file = a.list();

File temp = null;

for (int i = 0; i < file.length; i++) {

if (oldPath.endsWith(File.separator)) {

temp = new File(oldPath + file[i]);

} else {

temp = new File(oldPath + File.separator + file[i]);

}

if (temp.isFile()) {

FileInputStream input = new FileInputStream(temp);

FileOutputStream output = new FileOutputStream(newPath + “/” +

(temp.getName()).toString());

byte[] b = new byte[1024 * 5];

int len;

while ((len = input.read(b)) != -1) {

output.write(b, 0, len);

}

output.flush();

output.close();

input.close();

}

if (temp.isDirectory()) {//如果是子文件夹

copyFolder(oldPath + “/” + file[i], newPath + “/” + file[i]);

}

}

} catch (Exception e) {

LOG.error(“复制整个文件夹内容操作出错”);

e.printStackTrace();

}

}

/**

  • 获取一个文件的md5值(可处理大文件)

  • @param file

  • @return java.lang.String

  • @author zxzhang

  • @date 2020/3/23

*/

public static String getMD5(MultipartFile file) {

InputStream fileInputStream = null;

try {

MessageDigest MD5 = MessageDigest.getInstance(“MD5”);

fileInputStream = file.getInputStream();

byte[] buffer = new byte[8192];

int length;

while ((length = fileInputStream.read(buffer)) != -1) {

MD5.update(buffer, 0, length);

}

return new String(Hex.encodeHex(MD5.digest()));

} catch (Exception e) {

e.printStackTrace();

return null;

} finally {

try {

if (fileInputStream != null) {

fileInputStream.close();

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

/**

  • 获取一个文件的md5值(可处理大文件)

  • @param file

  • @return java.lang.String

  • @author zxzhang

  • @date 2020/3/23

*/

public static String getMD5(File file) {

try(FileInputStream fileInputStream = new FileInputStream(file)) {

MessageDigest MD5 = MessageDigest.getInstance(“MD5”);

byte[] buffer = new byte[8192];

int length;

while ((length = fileInputStream.read(buffer)) != -1) {

MD5.update(buffer, 0, length);

}

return new String(Hex.encodeHex(MD5.digest()));

} catch (Exception e) {

e.printStackTrace();

return null;

}

}

/**

  • 求一个字符串的md5值

  • @param target

  • @return java.lang.String

  • @author zxzhang

  • @date 2020/3/23

*/

public static String MD5(String target) {

return DigestUtils.md5Hex(target);

}

}

8、FileManagementHelper代码

/**

  • @description:

  • @author: zhangzhixiang

  • @createDate: 2019/12/11

  • @version: 1.0

*/

@Component

public class FileManagementHelper {

private static final Logger LOG = LoggerFactory.getLogger(FileManagementHelper.class);

@Autowired

private BootstrapConfig bootstrapConfig;

/**

  • 根据文件后缀判断类型

  • @param ext

  • @return java.lang.Integer

  • @author zxzhang

  • @date 2019/12/10

*/

public Integer judgeDocumentType(String ext) {

//视频类

if (VedioEnum.containKey(ext) != null) {

return ResourceTypeEnum.VIDEO.getCode();

}

//图片类

if (ImageEnum.containKey(ext) != null) {

return ResourceTypeEnum.IMAGE.getCode();

}

//文档类

if (DocumentEnum.containKey(ext) != null) {

return ResourceTypeEnum.FILE.getCode();

}

//未知

return ResourceTypeEnum.OTHER.getCode();

}

/**

  • 生成随机文件名称

  • @param ext

  • @return java.lang.String

  • @author zxzhang

  • @date 2019/12/10

*/

public static String createFileName(String ext) {

SimpleDateFormat simpleDateFormat = new SimpleDateFormat(“yyyyMMddHHmmss”);

return simpleDateFormat.format(new Date()) + (int) (Math.random() * 900 + 100) + ext;

}

/**

  • 获取文件后缀

  • @param fileName

  • @return java.lang.String

  • @author zxzhang

  • @date 2019/12/10

*/

public String getExt(String fileName) {

return fileName.substring(fileName.lastIndexOf(“.”) + 1);

}

/**

  • 获取文件所在目录

  • @param filePath

  • @return java.lang.String

  • @author zxzhang

  • @date 2019/12/10

*/

public String getFileDir(String filePath) {

return filePath.substring(0, filePath.lastIndexOf(BootstrapConst.PATH_SEPARATOR));

}

/**

  • 获取文件名

  • @param filePath

  • @return java.lang.String

  • @author zxzhang

  • @date 2019/12/10

*/

public String getFileName(String filePath) {

return filePath.substring(filePath.lastIndexOf(BootstrapConst.PATH_SEPARATOR) + 1, filePath.lastIndexOf(“.”));

}

}

9、PageObjUtils代码

/**

  • @Classname: com.openailab.oascloud.um.util.PageObjUtils

  • @Description: 分页对象工具类

  • @Author: ChenLiang

  • @Date: 2019/7/17

*/

@Component

public class PageObjUtils {

public PageVO getPageList(PageInfo personPageInfo) {

PageVO result = new PageVO();

if (personPageInfo != null) {

if (!personPageInfo.getList().isEmpty()) {

result.setPageNo(personPageInfo.getPageNum());

result.setPageSize(personPageInfo.getPageSize());

result.setTotal(Integer.valueOf(String.valueOf(personPageInfo.getTotal())));

result.setItems(personPageInfo.getList());

}

}

return result;

}

}

10、RedisDao代码

/**

  • @Classname: com.openailab.oascloud.datacenter.api.IRedisApi

  • @Description: Redis API

  • @Author: zxzhang

  • @Date: 2019/7/1

*/

@FeignClient(ServiceNameConst.OPENAILAB_DATA_CENTER_SERVICE)

public interface RedisDao {

/**

  • @api {POST} /redis/set 普通缓存放入并设置过期时间

  • @apiGroup Redis

  • @apiVersion 0.1.0

  • @apiParam {String} key 键

  • @apiParam {String} value 值

  • @apiParam {long} expire 过期时间

*/

@PostMapping(“/redis/set”)

ResponseResult set(@RequestParam(“key”) String key, @RequestParam(“value”) String value, @RequestParam(“expire”) long expire);

/**

  • @api {POST} /redis/get 普通缓存获取

  • @apiGroup Redis

  • @apiVersion 0.1.0

  • @apiParam {String} key 键

  • @apiSuccess {String} value 值

*/

@PostMapping(“/redis/get”)

String get(@RequestParam(“key”) String key);

/**

  • @api {POST} /redis/del 普通缓存删除

  • @apiGroup Redis

  • @apiVersion 0.1.0

  • @apiParam {String} key 键

*/

@PostMapping(“/redis/del”)

ResponseResult del(@RequestParam(“key”) String key);

/**

  • @api {POST} /redis/hset 存入Hash值并设置过期时间

  • @apiGroup Redis

  • @apiVersion 0.1.0

  • @apiParam {String} key 键

  • @apiParam {String} item 项

  • @apiParam {String} value 值

  • @apiParam {long} expire 过期时间

*/

@PostMapping(“/redis/hset”)

ResponseResult hset(@RequestParam(“key”) String key, @RequestParam(“item”) String item, @RequestParam(“value”) String value, @RequestParam(“expire”) long expire);

/**

  • @api {POST} /redis/hget 获取Hash值

  • @apiGroup Redis

  • @apiVersion 0.1.0

  • @apiParam {String} key 键

  • @apiParam {String} item 项

  • @apiSuccess {String} value 值

  • @apiSuccessExample {json} 成功示例

  • {“name”:“张三”,“age”:30}

*/

@PostMapping(“/redis/hget”)

Object hget(@RequestParam(“key”) String key, @RequestParam(“item”) String item);

/**

  • @api {POST} /redis/hdel 删除Hash值SaasAppKeyDao

  • @apiGroup Redis

  • @apiVersion 0.1.0

  • @apiParam {String} key 键

  • @apiParam {String} item 项

*/

@PostMapping(“/redis/hdel”)

ResponseResult hdel(@RequestParam(“key”) String key, @RequestParam(“item”) String item);

}

11、BootstrapConfig代码

/**

  • @Classname: com.openailab.oascloud.security.common.config.BootstrapConsts

  • @Description: 引导类

  • @Author: zxzhang

  • @Date: 2019/10/8

*/

@Data

@Configuration

public class BootstrapConfig {

最后

小编的一位同事在校期间连续三年参加ACM-ICPC竞赛。从参赛开始,原计划每天刷一道算法题,实际上每天有时候不止一题,一年最终完成了 600+:

凭借三年刷题经验,他在校招中很快拿到了各大公司的offer。

入职前,他把他的刷题经验总结成1121页PDF书籍,作为礼物赠送给他的学弟学妹,希望同学们都能在最短时间内掌握校招常见的算法及解题思路。

整本书,我仔细看了一遍,作者非常细心地将常见核心算法题和汇总题拆分为4个章节。

而对于有时间的同学,作者还给出了他结合众多数据结构算法书籍,挑选出的一千多道题的解题思路和方法,以供有需要的同学慢慢研究。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
ey, @RequestParam(“item”) String item, @RequestParam(“value”) String value, @RequestParam(“expire”) long expire);

/**

  • @api {POST} /redis/hget 获取Hash值

  • @apiGroup Redis

  • @apiVersion 0.1.0

  • @apiParam {String} key 键

  • @apiParam {String} item 项

  • @apiSuccess {String} value 值

  • @apiSuccessExample {json} 成功示例

  • {“name”:“张三”,“age”:30}

*/

@PostMapping(“/redis/hget”)

Object hget(@RequestParam(“key”) String key, @RequestParam(“item”) String item);

/**

  • @api {POST} /redis/hdel 删除Hash值SaasAppKeyDao

  • @apiGroup Redis

  • @apiVersion 0.1.0

  • @apiParam {String} key 键

  • @apiParam {String} item 项

*/

@PostMapping(“/redis/hdel”)

ResponseResult hdel(@RequestParam(“key”) String key, @RequestParam(“item”) String item);

}

11、BootstrapConfig代码

/**

  • @Classname: com.openailab.oascloud.security.common.config.BootstrapConsts

  • @Description: 引导类

  • @Author: zxzhang

  • @Date: 2019/10/8

*/

@Data

@Configuration

public class BootstrapConfig {

最后

小编的一位同事在校期间连续三年参加ACM-ICPC竞赛。从参赛开始,原计划每天刷一道算法题,实际上每天有时候不止一题,一年最终完成了 600+:

凭借三年刷题经验,他在校招中很快拿到了各大公司的offer。

入职前,他把他的刷题经验总结成1121页PDF书籍,作为礼物赠送给他的学弟学妹,希望同学们都能在最短时间内掌握校招常见的算法及解题思路。

整本书,我仔细看了一遍,作者非常细心地将常见核心算法题和汇总题拆分为4个章节。

而对于有时间的同学,作者还给出了他结合众多数据结构算法书籍,挑选出的一千多道题的解题思路和方法,以供有需要的同学慢慢研究。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-qrspNQh9-1713188516338)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值