postman 传递 raw 参数错误 org.springframework.web.bind.MissingServletRequestParameterException: Required I

问题描述

使用 postman 传递 raw 参数错误:
org.springframework.web.bind.MissingServletRequestParameterException: Required Integer parameter ‘xxx’ is not present

问题分析

端上传来的 content-type 对应的值为 application/json:
在这里插入图片描述

导致:
在这里插入图片描述

问题解决

端上将 content-type 修改为 application/x-www-form-urlencoded:
在这里插入图片描述

body 参数就会自动变为 x-www-form-urlencoded:
在这里插入图片描述

// HeartbeatController.java package com.ruoyi.dataAcquisition.controller; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @RestController @CrossOrigin(origins = "*") @SpringBootApplication(scanBasePackages = "com.ruoyi.dataAcquisition.controller") public class HeartbeatController { private static final ConcurrentHashMap<String, Long> clientStatus = new ConcurrentHashMap<>(); private static final long OFFLINE_THRESHOLD = 90000; @Operation(summary = "心跳上报接口") @GetMapping("/heartbeat") public ResponseEntity<Map<String, Object>> heartbeat( @Parameter(description = "设备唯一标识", required = true) @RequestParam String clientId ) { clientStatus.put(clientId, System.currentTimeMillis()); Map<String, Object> response = new HashMap<>(); response.put("status", "online"); response.put("clientId", clientId); return ResponseEntity.ok(response); } @Operation(summary = "设备状态查询接口") @GetMapping("/client-status") public ResponseEntity<Map<String, Object>> getClientStatus( @Parameter(description = "设备唯一标识", required = true) @RequestParam String clientId ) { Long lastBeat = clientStatus.get(clientId); boolean isOnline = lastBeat != null && (System.currentTimeMillis() - lastBeat) < OFFLINE_THRESHOLD; Map<String, Object> response = new HashMap<>(); response.put("status", isOnline ? "online" : "offline"); response.put("lastHeartbeat", lastBeat); return ResponseEntity.ok(response); } }这是自己创建的包的接口,为什么curl调用报错
最新发布
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

悄悄地努力

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值