[스프링] 컨트롤러 이해하기

구동현·2024년 1월 17일

스프링

목록 보기
8/21

Controller 이해하기

import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/hello")
public class HelloController {
    @GetMapping("/get")
    @ResponseBody // 순수하게 문자열만 반환
    public String hello() {
        return "Hello, world";
    }

    @PostMapping("/")
    @ResponseBody // 순수하게 문자열만 반환
    public String post() {
        return "post";
    }

    @PutMapping("/")
    @ResponseBody // 순수하게 문자열만 반환
    public String put() {
        return "put";
    }

    @DeleteMapping("/")
    @ResponseBody // 순수하게 문자열만 반환
    public String delete() {
        return "delete";
    }
}

@Controller

  • 이 클래스가 컨틀롤러임을 알리는 annotation

@RequestMapping("/hello")

@GetMapping("/get")

@PostMapping("/")

@PutMapping("/")

@DeleteMapping("/")

@ResponseBody

  • return 값을 문자열 그대로 리턴해준다.
profile
개발합시다

0개의 댓글