一:经过试验发现,如果使用如下的Controller(@RequestBody), 前台POST的请求body只能是JSON,如果是form-data, X-www-form-urlencoded 或者XML都会报415 Unsupported              Media Type错误

  @RequestMapping(value = "/users", method = RequestMethod.POST )
public String addUser(@RequestBody User user, HttpServletRequest request) {
userService.addUser(user);
return "OK";
}

二:如果要接受form-data / X-www-form-urlencoded:  可以用HttpServletRequest, 使用如下的方法来获得参数。

   request.getParameterNames()
   request.getParameter("AA")
   request.getParameterMap()
 @RequestMapping(value = "/users/new", method = RequestMethod.POST )
public String addUser( HttpServletRequest request) {
System.out.println(request.getQueryString());
return "OK";
}

三: form-data 和 X-www-form-urlencoded 有什么区别

form-data可以上传文件和键值对; X-www-form-urlencoded只能上传键值对。

												

Spring boot 学习 九的更多相关文章

  1. spring boot 学习(九)小工具篇:?秒防刷新

    注解 + 拦截器:?秒防刷新 小工具篇:工具许多都是我以前在 github 之类开源平台找到的小工具类,作者的信息什么的许多都忘了.先说声不好意思了.若有相关信息,麻烦提醒一下~ 解释 所谓的?秒防刷 ...

  2. Spring Boot 学习笔记(六) 整合 RESTful 参数传递

    Spring Boot 学习笔记 源码地址 Spring Boot 学习笔记(一) hello world Spring Boot 学习笔记(二) 整合 log4j2 Spring Boot 学习笔记 ...

  3. spring boot / cloud (九) 使用rabbitmq消息中间件

    spring boot / cloud (九) 使用rabbitmq消息中间件 前言 rabbitmq介绍: RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.它可以用于大型软件系统 ...

  4. Spring Boot学习大全(入门)

    Spring Boot学习(入门) 1.了解Spring boot Spring boot的官网(https://spring.io),我们需要的一些jar包,配置文件都可以在下载.添置书签后,我自己 ...

  5. Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客

    ==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...

  6. Spring boot学习1 构建微服务:Spring boot 入门篇

    Spring boot学习1 构建微服务:Spring boot 入门篇 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框 ...

  7. spring Boot(十九):使用Spring Boot Actuator监控应用

    spring Boot(十九):使用Spring Boot Actuator监控应用 微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台 ...

  8. spring boot 学习资料

    spring boot 学习资料: 学习资料 网址 Spring Boot Cookbook-极客学院 http://wiki.jikexueyuan.com/project/spring-boot- ...

  9. Spring Boot学习笔记2——基本使用之最佳实践[z]

    前言 在上一篇文章Spring Boot 学习笔记1——初体验之3分钟启动你的Web应用已经对Spring Boot的基本体系与基本使用进行了学习,本文主要目的是更加进一步的来说明对于Spring B ...

随机推荐

  1. OpenSUSE 13.1上安装StrongSwan

    结果: 1)iOS 7.1设备能够拨IPSec VPN到StrongSwan电脑上面来 - Connect to VPN 2)iOS 设备浏览器能够訪问StrongSwan VPN所在的内网地址服务器 ...

  2. PythonCookBook笔记——函数

    函数 可接受任意数量参数的函数 接受任意数量的位置参数,使用*参数. 接受任意数量的关键字参数,使用**参数. 只接受关键字参数的函数 强制关键字参数放在某个参数后或直接单个之后. 给函数参数增加元信 ...

  3. jquery Jsonp的使用

    <script type="text/javascript"> $(function(){ $.ajax({ url:"test", jsonpCa ...

  4. Html控件和Web控件(转)

    作为一名ASP.NET的初学者,了解并且区别一些混淆概念是很必须的,今天这篇博文 就是主要向大家介绍一下Html控件和Web控件.在ASP.net中,用户界面控件主要就是 Html控件和Web控件,在 ...

  5. 偏函数应用 pfa

  6. Flask:程序结构

    在Flask中需要配置各种各样的参数.比如设置秘钥,比如上一章介绍到的配置数据库类型. app.config['SECRET_KEY']=os.urandom(20) app.config['SQLA ...

  7. PowerDesigner 125 导致 Word 2007文档内容无法选中以及点击鼠标没用

  8. JS dom最常用API

    //document方法:    var cont = document.getElementByIdx_x('cont'); //className给标签添加class    cont.classN ...

  9. API的理解和使用——集合

    集合类型的命令及时间复杂度  区间 命令 功能 时间复杂度  集合内 sadd key element [element ... ]  添加元素 O(k),k是元素个数 srem key elemen ...

  10. Vue-router进阶、单页面应用(SPA)带来的问题

    一 . vue-router 进阶 回顾学过的vue-router,并参考官方文档学习嵌套路由等路由相关知识. 二 . 单页面应用(SPA)带来的问题 1 . 虽然单页面应用有优点 , 但是,如果后端 ...