博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring boot 1.3.5 PUT方法接收参数
阅读量:7034 次
发布时间:2019-06-28

本文共 951 字,大约阅读时间需要 3 分钟。

  hot3.png

单位Android客户端POST/PUT请求的contentType统一封装为Multipart/form-data,

后台服务使用框架为Spring Boot 1.3.5RELEASE。在使用默认配置时,Controller可以在POST请求中用request.getParameter("")正常接收参数,但遇到PUT请求时接收参数为空。

查找原因后发现springMVC默认的PUT处理没有包含multipart,试过多种配置后,在配置类(@Configuration)中加入以下代码即可正常处理:

@Beanpublic MultipartResolver multipartResolver() {    return new StandardServletMultipartResolver() {        @Override        public boolean isMultipart(HttpServletRequest request) {            String method = request.getMethod().toLowerCase();            //By default, only POST is allowed. Since this is an 'update' we should accept PUT.            if (!Arrays.asList("put", "post").contains(method)) { return false; }            String contentType = request.getContentType();            return (contentType != null &&contentType.toLowerCase().startsWith("multipart/"));        }    };}

原文地址:http://i-proving.com/tag/multipartform-data/

最后google大法好!

转载于:https://my.oschina.net/landas/blog/710031

你可能感兴趣的文章
科研经费管理新规定——劳务费从15%变为上不封顶
查看>>
linux -- Linux下的五个查找命令:grep、find、locate、whereis、which
查看>>
白话经典算法系列之七 堆与堆排序
查看>>
布局管理器之CardLayout(卡片布局管理器)
查看>>
Linux下Perl的安装(转)
查看>>
MySQL TCL 整理
查看>>
jack welch:“你们知道了,但是我们做到了”
查看>>
防重复请求处理的实践与总结
查看>>
PHP下ajax跨域的解决方案之CORS
查看>>
iOS10.3 起,将支持应用内评分
查看>>
【Discuz】ucenter通讯失败与Discuz的头像无法显示
查看>>
SQL Server 存储过程
查看>>
CSS样式----CSS样式表的继承性和层叠性(图文详解)
查看>>
android动画具体解释二 属性动画原理
查看>>
SpringMVC断言--Assert
查看>>
Windows编译OpenSSL
查看>>
BNUOJ34977夜空中最亮的星(数学,向量的应用)
查看>>
[Elasticsearch] 向已存在的索引中加入自己定义filter/analyzer
查看>>
…… are only available on JDK 1.5 and higher 错误
查看>>
远程连接MySql报错解决办法(2003)(1130)
查看>>