前端javascript发起post请求java端提供服务参数为ListObject请分别给出两端代码
<p>前端javascript发起post请求:</p>
<pre><code class="language-javascript">const data = {
list: [obj1, obj2, obj3]
};
fetch('/api/post', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(response => {
// handle response
}).catch(error => {
// handle error
});
</code></pre>
<p>Java端提供服务参数为List<Object>:</p>
<pre><code class="language-java">@RestController
public class MyController {
@PostMapping("/api/post")
public void post(@RequestBody List<Object> list) {
// handle list
}
}
</code></pre>
原文地址: http://www.cveoy.top/t/topic/cRkB 著作权归作者所有。请勿转载和采集!