1. @RequestParam

웹에서 사용자가 입력한 값을 자동으로 메소드에 전달해주는 도구

 @GetMapping("hello-mvc")
    public String helloMvc(@RequestParam("name") String name, Model model) {
        model.addAttribute("name", name);
        return "hello-template";
    }

1-1. 예시

@GetMapping("hello-mvc")
    public String helloMvc(@RequestParam("name") String name, Model model) {
        model.addAttribute("name", name);
        return "hello-template";
    }
2025-02-26T12:35:22.401+09:00  WARN 12388 
--- [hellospring] [nio-8080-exec-2] 
.w.s.m.s.DefaultHandlerExceptionResolver 
: Resolved 
[org.springframework.web.bind.MissingServletRequestParameterException
: Required request parameter 'name' for method parameter type String is not present]

이런 식으로 출력이 정상적으로 된다.

1-2. 동작방식

브라우저에서 직접 값을 입력하게 되면 Controller 의 메소드에서 name의 값이 name=spring!!으로 바뀌게 된다. 바뀐 값이 Model에 담기고, view로 넘어가서 hello-template.html 파일에서 <p th:text="'hello ' + ${name}">hello! empty</p> 부분의 name값이 입력된 값으로 치환된 후 변환 되어서 브라우저에 표시되는 방식이다.

캡처.PNG


2. API

스프링 프레임워크에서 제공하는 다양한 기능을 활용하여 애플리케이션 개발을 하게 돋는 인터페이스 및 클래스들의 집합 여러가지 모듈과 라이브러리로 구성되어있고, 이 모듈들이 제공하는 API는 주로 웹 앱, DB연결, 메시징, 트랜잭션 관리 등 다양한 분야에 걸쳐있다.

2-1. 주요특징