[SPRING] Spring @RequestParam 인수가 POST 메서드에서 전달되지 않음
SPRINGSpring @RequestParam 인수가 POST 메서드에서 전달되지 않음
Spring과 게시물 요청에 문제가 있습니다. Ajax 호출을위한 컨트롤러 메소드를 설정 중이며, 아래 메서드 정의를 참조하십시오.
@RequestMapping(value = "add.page", method = RequestMethod.POST)
@ResponseBody
public Object createComment(
@RequestParam(value = "uuid", required = false) String entityUuid,
@RequestParam(value = "type", required = false) String entityType,
@RequestParam(value = "text", required = false) String text,
HttpServletResponse response) {
....
HTML 호출을 어떤 방식으로 작성하든 관계없이 @RequestParam 매개 변수의 값은 항상 null입니다. 다른 많은 메소드가 있는데, 가장 큰 차이는 다른 메소드는 GET 메소드 인 반면, 이것은 POST라는 점입니다. @RequestParam을 POST 메서드와 함께 사용할 수 있습니까?
스프링 버전 3.0.7을 사용하고 있습니다. 릴리스 - 문제의 원인을 아는 사람이 있습니까?
Ajax 코드 :
$.ajax({
type:'POST',
url:"/comments/add.page",
data:{
uuid:"${param.uuid}",
type:"${param.type}",
text:text
},
success:function (data) {
//
}
});
해결법
-
==============================
1.문제는 제가 그 방법을 부르는 방식으로 밝혀졌습니다. 내 아약스 코드는 요청 매개 변수가 아닌 요청 본문의 모든 매개 변수를 전달하므로 내 @RequestParam 매개 변수가 모두 비어 있습니다. 내 아약스 코드를 다음과 같이 변경했습니다.
문제는 제가 그 방법을 부르는 방식으로 밝혀졌습니다. 내 아약스 코드는 요청 매개 변수가 아닌 요청 본문의 모든 매개 변수를 전달하므로 내 @RequestParam 매개 변수가 모두 비어 있습니다. 내 아약스 코드를 다음과 같이 변경했습니다.
$.ajax({ type: 'POST', url: "/comments/add.page?uuid=${param.uuid}&type=${param.type}", data: text, success: function (data) { // } });
또한 요청 본문에서 텍스트를 가져 오는 컨트롤러 메서드를 변경했습니다.
@RequestMapping(value = "add.page", method = RequestMethod.POST) @ResponseBody public Object createComment( @RequestParam(value = "uuid", required = false) String entityUuid, @RequestParam(value = "type", required = false) String entityType, @RequestBody String text, HttpServletResponse response) {
그리고 지금 나는 예상대로 매개 변수를 얻고 있습니다.
from https://stackoverflow.com/questions/14006619/spring-requestparam-arguments-not-being-passed-in-post-method by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] Spring 보안의 모든 요청에서 데이터베이스의 UserDetails 객체 다시로드 (0) | 2019.03.17 |
---|---|
[SPRING] 봄 표현 읽기 파일 내용 (0) | 2019.03.17 |
[SPRING] Spring RestTemplate 리디렉션 302 (0) | 2019.03.17 |
[SPRING] JPA와 Hibernate 주석 간의 관계 (0) | 2019.03.17 |
[SPRING] 스프링 웹 애플리케이션 상태 점검 (0) | 2019.03.17 |