package com.demo.controller; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import com.demo.util.Result; /* * 内容 */ @Controller @RequestMapping("upload") public class FileController { /* @Autowired private ContentMapper contentMapper;*/ /* * 上传视频 * 如果要携带别的 参数 用 这个 格式 @RequestParam("recordId") Integer recordId, * recordId 参数名字 */ @RequestMapping(value="video") @ResponseBody public Result uoloadVideo(@RequestParam("file") MultipartFile file,Model model,HttpServletRequest request, HttpServletResponse response) { Result result = new Result(); Map<String, Object> data = new HashMap<String, Object>(); String serverPath = "/upload/" + new SimpleDateFormat("yyyyMM").format(new Date()) + "/"; String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort(); String filePath = request.getSession().getServletContext().getRealPath(serverPath); String fileName = UUID.randomUUID().toString().replaceAll("-", "") + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); String fileUrl = request.getContextPath() + serverPath + fileName; File targetFile = new File(filePath, fileName); if (!targetFile.exists()) { targetFile.mkdirs(); } try { file.transferTo(targetFile); data.put("fileUrl", basePath+fileUrl); result = new Result(0, "上传成功", data); } catch (Exception e) { result = new Result(1, "上传异常"); } return result; } @RequestMapping(value="index") public String index( ) { return "index"; } }

sjc199 LV2
2022年6月13日
13613768985 LV1
2022年5月13日
han329574 LV8
2021年12月5日
空空空 LV1
2021年7月20日
871505903 LV4
2021年4月26日
lktkitty LV1
2020年12月7日
a770919458 LV1
2020年10月29日
无聊de人 LV1
2020年7月27日
yantingbin2012 LV1
2020年7月13日
liumingliang LV1
2020年7月11日

Ramon2019 LV1
1月22日
微信网友_6194929804660736
2022年10月28日
暂无贡献等级
mc0624
2022年10月17日
暂无贡献等级
微信网友_6114200435855360 LV1
2022年9月1日
49202046 LV7
2022年8月1日
hehe264 LV20
2022年6月30日
liys1234 LV9
2022年6月21日
sjc199 LV2
2022年6月13日
微信网友_5996860817444864 LV2
2022年6月12日
364502984 LV18
2022年6月2日