[Practice] 클라이언트 요청에 대한 주소 만들기 (4)

2021. 4. 12. 13:39Spring/Practice

1. 문제

  • Rest 컨트롤러 형식의 어노테이션 이용
  • 주소매핑은 Rest 형식의 어노테이션 이용
  • HTTP 메서드는 GET 방식
  • 리턴값은 "hello rest" 문자열 리턴
  • 주소는 "/hello-rest"




 

2. 풀이

package com.example.jpa.sample;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SecondController {

    // 문제 3
    @RequestMapping(value = "/hello-spring", method = RequestMethod.GET)
    public String helloSpring() {
        return "hello spring";
    }

    // 문제 4
    @GetMapping("/hello-rest")
    public String helloRest() {
        return "hello rest";
    }
}
728x90