美文网首页
springboot中controller接收参数

springboot中controller接收参数

作者: SmileMylife | 来源:发表于2019-07-06 16:33 被阅读0次

1.当前台发送的请求content-type为json时,后台接收时需要对入参打上requestbody注解,用于接收前台传入的json串,这种请求相当于将json字符串放在请求体中,后台然后接收了这个请求字符串,然后再通过转化成对象即可使用。示例如下:

var timeOut = setTimeout(function() {
      $.ajax("http://localhost:8080/testAjax", {
           type: "post",
           // contentType: "appplication/json",
          data: JSON.stringify({"username": "password"}),
      })
  }, 3000);

2.发送ajax请求时,默认使用的是form-data的形式进行发送的。

相关文章

网友评论

      本文标题:springboot中controller接收参数

      本文链接:https://www.haomeiwen.com/subject/ozaphctx.html