티스토리 뷰
1. 배열 전송하기
Client
Method : POST
Content-type : application/x-www-form-urlencoded; charset=UTF-8
$.ajax({
url: "/test",
dataType: "json",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
type: "post",
data: {ids : [1,2,3]},
success: function (res) {
},
error: function (request, status, error) {
}
});
Server
@PostMapping(value = "/test")
@ResponseBody
@ResponseStatus(HttpStatus.NO_CONTENT)
public void test(
@RequestParam(name = "ids[]", required = false) List<Integer> ids
) {
logger.info("ids : {}", ids);
}
2. 배열 전송하기(JSON)
Client
Method : POST
Content-type : application/json; charset=UTF-8
$.ajax({
url: "/test",
dataType: "json",
contentType: "application/json; charset=UTF-8",
type: "post",
data: JSON.stringify([1, 2, 3]),
success: function (res) {
},
error: function (request, status, error) {
}
});
Server
@PostMapping(value = "/test")
@ResponseBody
@ResponseStatus(HttpStatus.NO_CONTENT)
public void test(
@RequestBody(required = false) List<Integer> ids
) {
logger.info("ids : {}", ids);
}
3. 배열과 데이터 전송하기(JSON)
Client
Method : POST
Content-type : application/json; charset=UTF-8
$.ajax({
url: "/test",
dataType: "json",
contentType: "application/json; charset=UTF-8",
type: "post",
data: JSON.stringify({ids: [1, 2, 3], name: "kim"}),
success: function (res) {
},
error: function (request, status, error) {
}
});
Server
Json 데이터를 바인딩할 객체
public class Test {
private List<Integer> ids;
private String name;
//setter, getter 생략
}
@PostMapping(value = "/test")
@ResponseBody
@ResponseStatus(HttpStatus.NO_CONTENT)
public void test(
@RequestBody(required = false) Test test
) {
logger.info("test : {}", test);
}
'IT > Spring' 카테고리의 다른 글
[Spring Boot] Ajax를 이용해 이미지 정보를 객체 단위로 전송하는 방법 (0) | 2020.08.12 |
---|---|
[Spring Boot] ConstraintValidator Custom 하기 (0) | 2020.07.09 |
[Spring Boot] 클라이언트 디바이스 정보 확인하기 (0) | 2020.06.17 |
[Spring Boot] @ControllerAdvice을 이용한 Exception 처리 (2) | 2020.06.11 |
[Spring Boot] spring boot devtools (0) | 2020.02.27 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- tomcat8
- springsecurity
- mybatis
- MariaDB
- tomcat
- linux
- Thymeleaf
- Solid
- Design Pattern
- ERD
- java
- JDK
- IP
- hibernate
- Web Application Server
- spring
- FormData
- vue.js
- querydsl
- mysql
- Git
- github
- javascript
- spring boot
- AWS
- jpa
- springboot
- centos7
- S3
- maven
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함