Spring boot ajax 를 이용하여 리스트 VO 받기
2021. 7. 15. 12:10ㆍprogramming/spring-boot
728x90
데이터 임의 가공
var array = new Array();
for(var i=0; i<20; i++) {
var map = new Object();
map.id = "product_" + i;
map.data = 100;
array.push(map);
}
ajax 요청
$.ajax({
type: 'POST',
url: '/product',
data: JSON.stringify(array),
dataType: 'json',
contentType: 'application/json',
cache: false,
...
});
Product model
import lombok.Data;
@Data
public class Product {
private String id;
private int data;
}
Controller
@PostMapping("/product")
@ResponseBody
public JsonResponse postTest(@RequestBody List<Product> productList) {
}
받아온 결과
request body [Product(id=product_0, data=100), Product(id=product_1, data=100), Product(id=product_2, data=100), Product(id=product_3, data=100), Product(id=product_4, data=100), Product(id=product_5, data=100), Product(id=product_6, data=100), Product(id=product_7, data=100), Product(id=product_8, data=100), Product(id=product_9, data=100), Product(id=product_10, data=100), Product(id=product_11, data=100), Product(id=product_12, data=100), Product(id=product_13, data=100), Product(id=product_14, data=100), Product(id=product_15, data=100), Product(id=product_16, data=100), Product(id=product_17, data=100), Product(id=product_18, data=100), Product(id=product_19, data=100)]
728x90
'programming > spring-boot' 카테고리의 다른 글
Spring boot Version upgrade! (0) | 2021.01.26 |
---|---|
[SPRING BOOT] AJP CONNECTOR CVE-2020-1938 (2.2.5.RELEASE) (0) | 2020.12.10 |