前端javascript发起post请求java端提供服务参数分别为ListObject和bizID和sID请分别给出两端代码
前端JavaScript代码:
const data = {
list: [obj1, obj2, obj3], // List<Object>
bizID: '123456', // bizID
sID: '7890' // sID
};
fetch('/api/service', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Java代码:
@PostMapping("/api/service")
public ResponseEntity<?> processService(@RequestBody Map<String, Object> request) {
List<Object> list = (List<Object>) request.get("list");
String bizID = (String) request.get("bizID");
String sID = (String) request.get("sID");
// do something with the parameters
return ResponseEntity.ok().build();
}
``
原文地址: https://www.cveoy.top/t/topic/cRnr 著作权归作者所有。请勿转载和采集!