Spring MVC框架:第九章:文件上传

本文档详细解析了一线大厂Java面试中的常见问题,介绍了SpringMVC中的文件上传功能,包括配置、接收数据方法以及实战案例。同时强调了提升编程技能,如Mybatis源码理解和丰富知识的重要性。
摘要由CSDN通过智能技术生成

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

<input type=“file” …/>

2.jar包

commons-fileupload-1.3.jar和commons-io-2.0.1.jar

3.配置CommonsMultipartResolver

注意:id必须是multipartResolver

4.接收数据

①普通数据:和以前一样正常接收 ②文件数据:使用@RequestParam注解注入到MultipartFile类型的入参中

@RequestMapping(“/upload”)

public String upload(@RequestParam(“picture”) MultipartFile picture) {

return “…”;

}

③MultiPartFile类型

在这里插入图片描述

实战案例:

结构图

在这里插入图片描述

web.xml

<?xml version="1.0" encoding="UTF-8"?>

springDispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring-mvc.xml

1

springDispatcherServlet

/

spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns:context=“http://www.springframework.org/schema/context”

xmlns:mvc=“http://www.springframework.org/schema/mvc”

xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

<context:component-scan base-package=“com.handlers”/>

mvc:annotation-driven/

mvc:default-servlet-handler/

index.jsp

<%@ page language=“java” contentType=“text/html; charset=UTF-8”

pageEncoding=“UTF-8”%>

Insert title here

你看我的新头像牛逼吗?


总结

我们总是喜欢瞻仰大厂的大神们,但实际上大神也不过凡人,与菜鸟程序员相比,也就多花了几分心思,如果你再不努力,差距也只会越来越大。实际上,作为程序员,丰富自己的知识储备,提升自己的知识深度和广度是很有必要的。

Mybatis源码解析

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!
序员,丰富自己的知识储备,提升自己的知识深度和广度是很有必要的。

Mybatis源码解析

[外链图片转存中…(img-Dp4wzwgA-1714661571419)]

[外链图片转存中…(img-ZZ8lrcBY-1714661571420)]

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值