QueryString 입력
입력값을 얻어오는 방법
요청하는 것에 추가적인 질의를 할 경우 사용
공지사항 get방식 값 받아오기
HttpServletRequest 사용방법
Spring을 통해서 값을 입력받는 방법
스프링이 알아서 p라는 변수를 담아준다.
NoticeComtroller.java
package com.newlecture.web.controller.customer;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.newlecture.web.entity.Notice;
import com.newlecture.web.service.NoticeService;
@Controller
@RequestMapping("/customer/notice/")
public class NoticeComtroller {
@Autowired
private NoticeService noticeService;
@RequestMapping("list")
public String list(String p) throws ClassNotFoundException, SQLException {
//String p = request.getParameter("p");
System.out.println(p);
//List<Notice> list = noticeService.getList(1, "title", "");
return "notice.list";
}
@RequestMapping("detail")
public String detail() {
return "notice.detail";
}
}
QueryString 변수명과 기본값 처리
입력받을 때 변수명을 다른 것으로 하는 방법
값이 전달되지 않았을 경우 기본값 지정하기
정상적으로 실행됨을 확인
@RequestParam 옵션
Optional Element
스프링 제공 문서 보기
RequestParam (Spring Framework 5.3.4 API)
Whether the parameter is required. Defaults to true, leading to an exception being thrown if the parameter is missing in the request. Switch this to false if you prefer a null value if the parameter is not present in the request. Alternatively, provide a d
docs.spring.io
naem 속성의 별칭 value
required = false 필수 값 옵션 (매개변수 필요 여부를 설정)