背景:实体集合作为参数

 
数据准备:
1、实体类
class A
{
private int id;
private String name;
}
2、集合json字符串
[{"id":1,"name":"k1"},{"id":2,"name":"k2"}]
 
 
前后端:
1、Java后端
  @RequestMapping(value = "/insertBatch.do")
  @ResponseBody
    public Result insertBatch(@RequestBody A[] params) {     //这里需要用数组,不能用集合
 
 
2、前端ajax调用
var dataArr=[{"id":1,"name":"k1"},{"id":2,"name":"k2"}];
var params = JSON.stringify(dataArr);
    $.ajax({
            type: 'POST',
            url: "http://localhost:8080/insertBatch.do",
            data: params,
            success:  function (data, status) {
                alert("数据: \n" + data + "\n状态: " + status);
            },
            dataType : 'json',
            contentType : 'application/json'
        });

相关文章:

  • 2021-11-13
  • 2021-11-05
  • 2021-07-04
  • 2021-12-26
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-10-21
相关资源
相似解决方案