src/main/java/cn/hxh/files/controller/FileController.java
(开头部分) 7KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package cn.hxh.files.controller;
import cn.hxh.files.pojo.Files;
import cn.hxh.files.pojo.PageResult;
import cn.hxh.files.pojo.Score;
import cn.hxh.files.pojo.User;
import cn.hxh.files.service.FilesService;
import cn.hxh.files.service.ScoreService;
import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.*;
@Controller
@RequestMapping("/file")
public class FileController {
@Autowired
private FilesService filesService;
@Autowired
private ScoreService scoreService;
@PostMapping("/upload")
public String upload(@RequestParam("file") MultipartFile[] file, HttpSession session) throws Exception {
for (MultipartFile multipartFile : file) {
getUser(multipartFile);
//文件大小
long size = multipartFile.getSize();
//老文件名字
String originalFilename = multipartFile.getOriginalFilename();
//文件类型
String contentType = multipartFile.getContentType();
//获取文件后缀名
String[] split = contentType.split("/");
String ext = "." + split[1];
//获取下载路径url
String s = ResourceUtils.getURL("classpath:").getPath() + "static/upload";
String url = URLDecoder.decode(s);
Files files = new Files();
files.setExt(ext);
//创建新文件名字
String newFileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + UUID.randomUUID().toString().replace("-", "") + ext;
files.setNewfilename(newFileName);
files.setOldfilename(originalFilename);
files.setSize(size);
后面还有 144 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
