zoukankan      html  css  js  c++  java
  • springMVC处理multipart/form-data类型的表单数据

    1、前端做好form表单

    <form action="${pageContext.request.contextPath}/fileUploadTest"
            method="post" enctype="multipart/form-data">
            <label>编号:</label> <input type="text" name="device" id="device">
            <br> <label>日期:</label> <input type="datetime-local"
                name="localDate" id="localDate"> <br> <label>选择文件:</label>
            <input type="file" name="file1" id="file1"> <br> <input
                type="submit" id="fileUpdate" value="点击上传文件"> <br> <input
                type="hidden" id="ssFile" name="ssFile">
        </form>

    2、在applicationContext.xml中进行配置

        <!-- 用于文件上传、下载的配置 -->
        <bean id="multipartResolver"
            class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="defaultEncoding" value="utf-8"></property>
            <property name="maxUploadSize" value="2097152"></property>
        </bean>

    3、controller中直接获取

    /**
         * 测试是否能上传文件
         * 
         * @return
         */
        @RequestMapping(value = "/fileUploadTest")
        @ResponseBody
        public String fileUploadTest(String device, String localDate, MultipartFile file1) {
            System.out.println(device + "," + localDate + "," + file1);return "yes";
        }
  • 相关阅读:
    nginx源码分析——http模块
    linux 信号处理
    文件读写监控(inotify, systemtap)
    rem
    vscode 将本地项目上传到码云
    vue 模拟去哪网
    form 文件上传
    分页
    修改默认select样式
    模拟select下拉框、复选框效果
  • 原文地址:https://www.cnblogs.com/jndx-ShawnXie/p/11747393.html
Copyright © 2011-2022 走看看