@RequestParam 주석 추가 와 추가 하지 않 는 것 은 별 차이 가 있 습 니 다.
1907 단어 RequestParam주해
요청 한 인 자 를 받 을 때@RequestParam 주 해 를 자주 사용 합 니 다.
그런데 가끔 은 이 주 해 를 넣 지 않 아 도 인 자 를 정상적으로 받 을 수 있 는 것 같다?
2.구별
지금 두 가지 방법 이 있어 요.
요청"/out1"주석 없 음
요청"/out2"에@RequestParam 주석 을 달 았 습 니 다.

브 라 우 저 에서 out1 과 out2 를 직접 방문 합 니 다.
out1 출력 null
잘못


주 해 를 붙 였 으 니 파 라 메 터 를 밝 혀 야 정상적으로 접근 할 수 있 습 니 다.

3.확장
@RequestParam 주 해 를 사용 할 때 다음 속성 을 흔히 볼 수 있 습 니 다.
1.defaultValue 기본 값 설정

정상 방문


2.value 매개 변수 이름 변경
요청 에 있 는 인자 이름 을 가리 키 지 않 을 때 기본적으로 형 삼 이름과 대응 합 니 다.
지금 value 속성 을 추가 하 였 습 니 다.

다시 접근 합 니 다.인자 이름 이 str 일 때 기본 값 hello 를 표시 합 니 다.

name 으로 변경 하면 정상적으로 받 을 수 있 습 니 다.

기본 값 과 마찬가지 로 인자 이름 은 대소 문자 가 민감 합 니 다.

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Spring이 @Value 메모를 통해 속성을 주입하는 몇 가지 방법에 대해 자세히 설명합니다.장면 만약 다음 속성 파일 dev.properties가 있다면, 아래의 tag를 주입해야 합니다 tag=123 PropertyPlaceholderConfigurer를 통해 코드 PreferencesPlaceholde...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.