본문 바로가기

WINK-(Web & App)/Spring Boot 스터디

[2025 겨울방학 스프링 스터디] 정채은 #1주차

반응형

 섹션 1

1. 프로젝트 생성

프로젝트 생성

 

main

 java

  hello. hello.spring

성공한겨

둘다 인텔리제이로 바꿔주기 

 

build. gradle 파일 선택

 

실제 라이브러리 선택 ㅡ> external library 파일 

 

 

3. 환경설정 

섹션 2

1. 정적 컨텐츠

 

 

 

 

2. MVC와 템플릿 엔진

mvc : model, view, controller

 

-

컨트롤러랑 뷰를 나눠서 생각해.

뷰 : 화면과 관련된 거

 

 

 

 

 

이미지

 

3. API

@GetMapping("hello-api")
    @ResponseBody
    public Hello helloApi(@RequestParam("name") String name) {
        Hello hello = new Hello();
        hello.setAge(15);
        hello.setName(name);
        hello.setNext(new Hello());
        hello.getNext().setName(name);
        hello.getNext().setAge(16);

        return hello;
    }

    static class Hello {
        private String name;
        private int age;
        private Hello next;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public Hello getNext() {
            return next;
        }

        public void setNext(Hello next) {
            this.next = next;
        }
    }

 

 

객체로 넣는 방법

@GetMapping("hello-api")    //Api 방식  -  @ResponseBody 객체 반환   - 데이터를 넣어줄때
    @ResponseBody
    public Hello helloApi(@RequestParam("name") String  name){
        Hello hello = new Hello(); //객체 생성
        hello.setName(name);
        return hello;  //객체를 넘김
    }

    static class Hello {    //getter and setter 
       private String name;     //외부에서 못꺼냄

        public String getName() {   //메서드를 통해 접근
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }  //-- 대표적인 API 반환 형식
    }
반응형