Dev.끄적끈적

Spring 입문 week1 본문

Spring

Spring 입문 week1

YeouidoSexyDeveloper 2022. 3. 18. 19:41

Person.java 에서 set과 get을 만들어줌.

package com.sparta.week01.prac;

public class Person {
    private String name;
    private int age;
    private String address;
    private String job;

    public Person(){

    }

    public Person(String names, int ages, String addresses, String jobs){
        this.name = names;
        this.age = ages;
        this.address = addresses;
        this.job = jobs;
    }

    public void setName(String names){
        this.name = names;
    }
    public void setAge(int ages){
        this.age = ages;
    }
    public void setAddress(String addresses){
        this.address = addresses;
    }
    public void setJob(String jobs){
        this.job = jobs;
    }

    public String getName(){
        return this.name;
    }
    public int getAge(){
        return this.age;
    }
    public String getAddress(){
        return this.address;
    }
    public String getJob(){
        return this.job;
    }
}

PersonController.java : allow the server to get /person data

package com.sparta.week01.controller;

import com.sparta.week01.prac.Course;
import com.sparta.week01.prac.Person;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PersonController {
    @GetMapping("/person")
    public Person getPerson() {
        Person p = new Person();
        p.setName("이 건 도");
        p.setAge(30);
        p.setAddress("여의도");
        p.setJob("재벌");
        return p;
    }
}

'Spring' 카테고리의 다른 글

Controller, Service, Repository 역할, 분리  (0) 2022.03.27
리팩토링이란?  (0) 2022.03.27
HTTP 메시지 이해하기  (0) 2022.03.26
IntelliJ Annotation processing 설정  (0) 2022.03.24
Spring 입문 강의 Notion 링크  (0) 2022.03.23