前后端交互

1.参数传递

后端,这种事传几个参数进来的,不是json

@PostMapping("/list")
public Result<?> findPage(@RequestParam(defaultValue = "1") Integer current,
                             @RequestParam(defaultValue = "10") Integer size,
                             @RequestParam(defaultValue = "") String search) {
       System.out.println("pageNum:"+current);
       System.out.println("pageSize:"+size);
       System.out.println("search:"+search);
}

apipost工具,后端能拿到三个值 content-type:application/x-www-form-urlencoded

在这里插入图片描述

前端

this.$request({
       url: "/order/list",
       method: "POST",
       params: {//这样传的是content-type:application/x-www-form-urlencoded
         "current":1,
         "size":5,
         "search":"张"
       }
}).then(res => {
       console.log(res.data)
})

在这里插入图片描述

2.参数传递2

@RequestMapping("/login")
    public Result<?> login(
            @RequestParam(value = "code", required = false) String code,
            @RequestParam(value = "rawData", required = false) String rawData,
            @RequestParam(value = "signature", required = false) String signature,
            @RequestParam(value = "encryptedData", required = false) String encryptedData,
            @RequestParam(value = "iv", required = false) String iv
    ) {
        System.out.println("code:" + code);
        System.out.println("rawData:" + rawData);
        System.out.println("signature" + signature);
        System.out.println("encryptedData" + encryptedData);
        System.out.println("iv" + iv);
uni.request({
									url: 'http://localhost:8080/renren-fast/apartment/user/login',
									method: "POST",
									header:{
										"content-type":"application/x-www-form-urlencoded"
									},
									data: {
										code: infoRes.code, //临时登录凭证
										rawData: rawData, //用户非敏感信息
										signature: signature, //签名
										encryptedData: encryptedData, //用户敏感信息
										iv: iv //解密算法的向量
									},
									success: (res) => {
										console.log(res)

									}
								})
							}

3.json传递

后端,传json,对象形式

@PostMapping("/save")
public Result<User> save(@RequestBody User user) {

}

apipost工具,json形式传对象, content-type:application/json

在这里插入图片描述

前端

this.$request({
        url: "/order/list",
        method: "POST",
        data: {//这样传的是content-type:application/json
          "current":1,
          "size":5,
          "search":"张"
        },
}).then(res => {
  		console.log(res.data)
})

在这里插入图片描述

4.ajax json传递

$.ajax({
            type: 'post',
            url: '${pageContext.request.contextPath}/parkingTimeController/addTime',
            contentType: "application/json;charset=utf-8",
            data:JSON.stringify({
                "carId": carId,
                "time":time,
                "pId": pId
            }),
            //     {
            //     "carId":carId,
            //     "beginTime":time,
            //     "pId":pId
            // },
            dataType: 'json',
            success: function (result) {


            }

        })
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值