• 스프링 시작하기 #2

    2021. 3. 9. 17:01

    by. 위지원

    정적 컨텐츠: 파일을 그대로~

    MVC와 템플릿 엔진: 템플릿 엔진을 MVC 방식으로 쪼개서, view를 템플릿 엔진으로 html을 좀 더 프로그래밍한거로 랜더링 해서 이 html을 client에게 전달

    API: 객체 전달

     

    @Controller
    public class HelloController {
    //기본
    @GetMapping("hello")
    public String hello(Model model){
    model.addAttribute("data","hello!");
    return "hello";
    }
    //mvc
    @GetMapping("hello-mvc")
    public String heeloMvc(@RequestParam(value = "name", required = false) String name, Model model){
    model.addAttribute("name",name);
    return "hello-template";
    }
    //response body, 단순 문자열
    @GetMapping("hello-string")
    @ResponseBody
    public String helloString(@RequestParam("name") String name){
    return "hello" + name;
    }
    //response body, 객체 전달
    @GetMapping("hello-api")
    @ResponseBody
    public Hello helloApi(@RequestParam("name") String name){
    Hello hello = new Hello();
    hello.setName("jiwonWee");
    return hello;
    }
    static class Hello{
    private String name;
    public String getName(){
    return this.name;
    }
    public void setName(String name){
    this.name = name;
    }
    }
    }
    profile
    위지원

    데이터 엔지니어로 근무 중에 있으며 데이터와 관련된 일을 모두 좋아합니다!. 특히 ETL 부분에 관심이 가장 크며 데이터를 빛이나게 가공하는 일을 좋아한답니다 ✨

    '2021년 > 개발공부' 카테고리의 다른 글