@RequestParam (2) API- @ResponseBody http://localhost:8080/hello-string?name=ayon @ResponseBody를 사용하면 뷰 리졸버(viewResolver)를 사용하지 않고 HTTP의 BODY에 문자 내용을 직접 반환한다. (HTML의 가 아님 !!) 단순 문자열인 hello ayon이 출력된다. 페이지 소스 보기 하더라도 소스가 따로 없고 문자열만 나타남. //문자 반환 @Controller public class HelloController { @GetMapping("hello-string") @ResponseBody public String helloString(@RequestParam("name") String name) { return "hello " + name; } } http://localhos.. MVC 패턴- @RequestParam http://localhost:8080/hello-mvc?name=ayon 실행 -> @RequestParam("name") String name > String 타입의 이름이 name인 변수에 ayon을 담는다. -> model.addAttribute("name", name); > model을 통해 name=ayon 값을 넘겨준다. -> hello-template.html을 return 한다. // @RequestParam(name = "name", required = false) 일 경우 http://localhost:8080/hello-mvc 를 실행하면 name=null 이 넘어가게 된다. required의 default는 true 인데 true의 경우 name 에 값을 담아주지 않으면 오류페이지.. 이전 1 다음