[Spring] 스프링에서 select, option 태그 값 넘기기(jsp 👈🏻👉🏻 controller 👉🏻 Service)

2022. 12. 7. 13:39·🚀 from error to study/Java

 

 

 

💻 jsp

✔️ select, option, 검색창, 검색 버튼 태그가 같은 form 태그 내에 존재해야 함

✔️ form 태그의 action 속성으로 url mapping 값 주기

✔️ select 태그에 name 속성 주기

✔️ option 태그에 value 값과 name 값 주기

<div id="selectCommentInfo">
    <form action="searchComment.ad" method="get">
        <select id="selectCommentMenu" name="condition">
            <option value="userId" name="userId">이메일</option>
            <option value="userNickname" name="userNickname">닉네임</option>
            <option value="contentsTitle" name="contentsTitle">콘텐츠명</option>
        </select>
        <input type="text" id="inputUserMail" name="keyword" value="${ keyword }" placeholder="검색할 유저의 정보를 입력하세요">&nbsp;
        <button type="submit" id="selectButton">검색</button>
    </form>
</div>

 

💻 Controller

✔️ 컨트롤러에서는 jsp의 select 태그, 검색창의 name값과 동일한 매개변수를 받아오기만 하면 됨

	@RequestMapping(value="searchComment.ad")
	public String searchAdminCommentList(String condition, String keyword) {
		
		System.out.println("condition: " + condition);
		System.out.println("keyword: " + keyword);
        
		return "admin/adminCommentView";
		
	}

 

 

 

 

 

💻 Controller에서 HashMap으로 가공 후 Service단으로 넘기기

HashMap<String, String> map = new HashMap<>();
		map.put("condition", condition);
		map.put("keyword", keyword);
        
ArrayList<Review> searchList = reviewService.searchAdminCommentList(map);

 

💻 Controller에서 DB까지 다녀온 데이터를 다시 jsp로 넘기기

model.addAttribute("searchList", searchList);

 

 

 

저작자표시 비영리 변경금지 (새창열림)
'🚀 from error to study/Java' 카테고리의 다른 글
  • [Spring] Error - The method get/set필드명() is undefined for the type VO클래스
  • [Spring] WARN : org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class java.lang.Integer] with preset Content-Type 'null']
  • TO_CHAR(컬럼이름, 'FM0.0')을 이용해 별점 포맷 '★0.0' 소수점 1자리까지 나오게 하기
  • [JSTL] JSTL 구문 적용했을 때 CSS 안 먹힘
천재강쥐
천재강쥐
  • 천재강쥐
    디버거도 버거다
    천재강쥐
  • 전체
    오늘
    어제
    • Category (467)
      • 진짜 너무 궁금한데 이걸 나만 몰라...? (0)
      • 💾 Portfolio (2)
      • 🐤 CodingTest (28)
        • Java (20)
        • ᕕ(ꐦ°᷄д°᷅)ᕗ❌ (5)
      • 🚀 from error to study (142)
        • AI (1)
        • Cloud (2)
        • DB (12)
        • Front-End (16)
        • Github (14)
        • Java (39)
        • Mac (7)
        • Normal (29)
        • Server (22)
      • 📘 certificate (44)
        • 📘 리눅스마스터1급 (1)
        • 📘⭕️ 정보처리기사 (40)
        • 📘⭕️ SQLD (3)
      • 📗 self-study (234)
        • 📗 inflearn (35)
        • 📗 생활코딩 (8)
        • 📗 KH정보교육원 당산지원 (190)
      • 🎨 Scoop the others (0)
        • 📖 Peeking into other people.. (0)
        • 🇫🇷 (0)
        • 📘⭕️ 한국사능력검정시험 심화 (11)
        • 오블완 (4)
  • 인기 글

  • hELLO· Designed By정상우.v4.10.1
천재강쥐
[Spring] 스프링에서 select, option 태그 값 넘기기(jsp 👈🏻👉🏻 controller 👉🏻 Service)
상단으로

티스토리툴바