pilipili在线视频网站开发日志(二)

2021-05-05 05:29

阅读:445

标签:mat   desc   视频   session   视频标题   一点   url   common   public   

今天在进行文件上传逻辑的编写

在jsp页面加上了enctype="multipart/form-data"

 1             form action="doUpload" method="post" enctype="multipart/form-data">
 2                 div class="form-group fg1" style="margin-top: 30px; ">
 3                     input type="file" name="video" value="上传视频" style="position:absolute;opacity: 0;">
 4                     span>选择上传视频  i class="icon-download-alt icon-2x">i>span>
 5                 div>
 6 
 7                 div class="form-group">
 8                     input type="text" placeholder="视频标题" name="title">
 9                 div>
10                 div class="form-group">
11                     input type="text" placeholder="给你的视频一点表述吧" name="desc">
12                 div>
13                 div class="form-group">
14                     select name="type" id="category_name" >
15                         option value="">选择类型option>
16                         option value="animation">动漫option>
17                         option value="dance">舞蹈option>
18                         option value="game">游戏option>
19                         option value="ghost">鬼畜option>
20                         option value="movie">电影option>
21                     select>
22                 div>
23 
24                 div class="form-group">
25                     input type="submit" value="投稿">
26                 div>
27 
28             form>

 

在controller里,写了@RequestParam("video") MultipartFile file

 1     @PostMapping("doUpload")
 2     public String doUpload(HttpSession session, HttpServletRequest request, @RequestParam("video") MultipartFile file){
 3         //, @RequestParam("video") MultipartFile file, Video video, String title, String desc, String category_name
 4         Logger logger = LoggerFactory.getLogger(UserController.class);
 5         String fileUrl = file.getOriginalFilename();
 6         Video media = new Video();
 7         media.setName(request.getParameter("title"));
 8         media.setDesc(request.getParameter("desc"));
 9         logger.info("视频名称为:" + media.getName() + " 视频描述为:" + media.getDesc() + " 视频类型为:" + request.getParameter("type"));
10         logger.info(fileUrl);
11         return "upload";

在springmvc中,写了bean标签

1     bean id="multipartResolver"
2           class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
3         
4         property name="defaultEncoding" value="UTF-8">property>
5         
6         property name="maxUploadSize" value="99999999">property>
7     bean>

 

可是!!!仍然报错

后来发现!

居然是pom文件内没有导入所需要的包!!!!

    dependency>
      groupId>commons-fileuploadgroupId>
      artifactId>commons-fileuploadartifactId>
      version>1.3.2version>
    dependency>

    
    dependency>
      groupId>commons-iogroupId>
      artifactId>commons-ioartifactId>
      version>2.5version>
    dependency>

一定要导入啊啊啊啊!!!

pilipili在线视频网站开发日志(二)

标签:mat   desc   视频   session   视频标题   一点   url   common   public   

原文地址:https://www.cnblogs.com/ABKing/p/12109909.html


评论


亲,登录后才可以留言!