Skip to content

fix(sample): 글 등록 후 목록으로 돌아올 때 검색 조건이 풀리는 문제 수정 - #47

Merged
jei007 merged 1 commit into
eGovFramework:mainfrom
wantaekchoi:fix/addsample-redirect-list-state
Sep 3, 2026
Merged

jei007 merged 1 commit into
eGovFramework:mainfrom
wantaekchoi:fix/addsample-redirect-list-state

Conversation

@wantaekchoi

Copy link
Copy Markdown
Contributor

수정 사유 Reason for modification

소스를 수정한 사유가 무엇인지 체크해 주세요. Please check the reason you modified the source. ([X] X는 대문자여야 합니다.)

  • 버그수정 Bug fixes
  • 기능개선 Enhancements
  • 기능추가 Adding features
  • 기타 Others

수정된 소스 내용 Modified source

검토자를 위해 수정된 소스 내용을 설명해 주세요. Please describe the modified source for reviewers.

문제

addSample 은 redirect:/egovSampleList.do 로 끝나면서 목록 상태를 하나도 붙이지 않습니다. 같은 컨트롤러의 updateSample 과 deleteSample 은 redirectAttributes 로 searchCondition searchKeyword pageIndex 를 붙여 보냅니다.

값이 없어서가 아닙니다. 등록 화면 egovSampleRegister.jsp 는 세 값을 히든 필드로 조건 없이 실어 보내므로 addSample 의 sampleVO 에도 그대로 들어와 있습니다. 받아 놓고 쓰지 않습니다.

그래서 검색 결과에서 글을 등록하면 검색 조건이 풀린 전체 목록으로 돌아옵니다. mvn package 로 만든 WAR 를 tomcat:10.1-jdk17-temurin 에 올려 받은 값입니다.

[1] GET  /egovSampleList.do?searchCondition=0&searchKeyword=0011&pageIndex=1 -> 200  6건
[2] POST /addSample.do    -> 302  Location: /egovSampleList.do
    따라가면 -> 200  10건 (검색 조건이 풀린 전체 목록 1페이지)
[3] POST /updateSample.do -> 302  Location: /egovSampleList.do?searchCondition=0&searchKeyword=0011&pageIndex=1
[4] POST /deleteSample.do -> 302  Location: /egovSampleList.do?searchCondition=0&searchKeyword=0011&pageIndex=1

의도한 제거가 아니라 v5.0.0 의 누락으로 보입니다

fc0f784 이전에는 세 핸들러가 모두 같은 세 줄을 갖고 있었습니다.

model.addAttribute("searchCondition", sampleVO.getSearchCondition());
model.addAttribute("searchKeyword", sampleVO.getSearchKeyword());
model.addAttribute("pageIndex", sampleVO.getPageIndex());

fc0f784 는 updateSample 과 deleteSample 에서 이 세 줄을 redirectAttributes.addAttribute(...) 로 바꿨고, addSample 에서는 지우기만 하고 대신 넣지 않았습니다. 같은 커밋의 같은 파일 안에서 갈렸고, 그 커밋이 addSample 의 시그니처도 함께 다시 썼습니다.

수정

updateSample 의 파라미터 순서와 본문 배치를 그대로 따랐습니다.

-	public String addSample(@Valid @ModelAttribute("sampleVO") SampleVO sampleVO, BindingResult bindingResult, Model model, SessionStatus status) throws Exception {
+	public String addSample(@Valid @ModelAttribute("sampleVO") SampleVO sampleVO, BindingResult bindingResult,
+			Model model, RedirectAttributes redirectAttributes, SessionStatus status) throws Exception {
 
 		sampleService.insertSample(sampleVO);
 		status.setComplete();
 
+		redirectAttributes.addAttribute("searchCondition", sampleVO.getSearchCondition());
+		redirectAttributes.addAttribute("searchKeyword", sampleVO.getSearchKeyword());
+		redirectAttributes.addAttribute("pageIndex", sampleVO.getPageIndex());
+
 		return "redirect:/egovSampleList.do";

검증 오류로 등록 화면을 다시 그리는 경로(bindingResult.hasErrors())는 그대로 두었습니다.

#45 와의 관계

지금 브라우저에서 목록 화면을 거쳐 등록으로 넘어오는 pageIndex 는 언제나 1 입니다. egovSampleList.jsp 의 히든 pageIndex 가 상수 1 이기 때문입니다.

GET  /egovSampleList.do?searchCondition=1&searchKeyword=Runtime&pageIndex=3
  listForm 히든 = {searchCondition: 1, searchKeyword: Runtime, pageIndex: 1}
POST /addSampleView.do
  등록 화면 히든 = {searchCondition: 1, searchKeyword: Runtime, pageIndex: 1}

그래서 이 수정으로 지금 당장 되살아나는 것은 검색 조건과 검색어이고, 페이지 번호는 그 히든 필드가 고쳐진 뒤에 의미가 생깁니다. 그 한 줄은 #45 로 따로 올렸습니다. 두 PR 은 파일이 겹치지 않아 순서에 상관없이 반영하실 수 있습니다.

JUnit 테스트 JUnit tests

테스트를 완료하셨으면 다음 항목에 [대문자X]로 표시해 주세요. When you're done testing, check the following items.

  • JUnit 테스트 JUnit tests
  • 수동 테스트 Manual testing

EgovSampleControllerAddSampleRedirectTest 를 함께 넣었습니다. 같은 값을 담은 SampleVO 로 updateSample 과 addSample 을 호출해 돌려준 뷰 이름과 RedirectAttributes 를 비교합니다. 문자열 대조가 아니라 실제 호출 결과 비교입니다.

수정 전 실패 메시지입니다.

EgovSampleControllerAddSampleRedirectTest.test  등록도 수정과 같은 목록 상태를 돌려줘야 한다.
update={searchCondition=0, searchKeyword=0011, pageIndex=3}, add={}

수정 후에는 통과합니다. pom.xml 의 surefire skipTests 가 true 로 고정돼 있어 그대로는 실행되지 않으니, 확인하실 때 그 값만 내려 주십시오.

저장소의 스프링 통합 테스트 EgovSampleControllerTestAddSampleTest 는 현재 main 에서도 HV000183(EL 의존성) 으로 뜨지 않아, 이 검증은 컨트롤러 단위로 짰습니다.

컨트롤러 변경만 남기는 편을 선호하시면 테스트는 빼겠습니다.

테스트 브라우저 Test Browser

테스트를 진행한 브라우저를 선택해 주세요. Please select the browser(s) you ran the test on. (다중 선택 가능 you can select multiple) [X] X는 대문자여야 합니다.

  • Chrome
  • Firefox
  • Edge
  • Safari
  • Opera
  • Internet Explorer
  • 기타 Others

브라우저 대신 세션 쿠키를 유지하는 명령행 HTTP 클라이언트로 확인했습니다.

테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video

테스트 전과 후의 스크린샷 또는 캡처 영상을 이곳에 첨부해 주세요. Please attach screenshots or video captures of your before and after tests here.

스크린샷 대신 수정 후에 받은 값을 옮깁니다. 컨테이너를 새로 띄운 직후의 초기 데이터에서 위와 같은 순서로 요청했습니다.

[1] GET  /egovSampleList.do?searchCondition=0&searchKeyword=0011&pageIndex=1 -> 200  6건
[2] POST /addSample.do    -> 302  Location: /egovSampleList.do?searchCondition=0&searchKeyword=0011&pageIndex=1
    따라가면 -> 200  7건 (새로 등록한 글이 검색 조건에 걸려 한 건 늘었습니다)
[3] POST /updateSample.do -> 302  Location: /egovSampleList.do?searchCondition=0&searchKeyword=0011&pageIndex=1
[4] POST /deleteSample.do -> 302  Location: /egovSampleList.do?searchCondition=0&searchKeyword=0011&pageIndex=1

세 액션의 Location 이 같아집니다.

@jei007 jei007 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

표준프레임워크에 대한 지속적인 참여에
대단히 감사드립니다.

@jei007
jei007 merged commit 2fb16f3 into eGovFramework:main Sep 3, 2026
1 check passed
@wantaekchoi
wantaekchoi deleted the fix/addsample-redirect-list-state branch September 3, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants