접근제어자 + return 타입 + 메서드명 + ()
접근제어자 : public, private, protected 등
return 타입 : 배열타입 중에서 int[], 객체타입 중에서 String, Integer, 데이터타입 중에서 int, boolean, char 등
접근제어자 + void + 메서드명 + ()
❗반환 타입이 없을 경우는 void 사용❗
접근제어자 + static + 메서드명 + ()
❗static 이 붙은 변수나 메서드는 클래스 레벨에서 공유되며, 객체 인스턴스를 생성하지 않고도 직접 접근할 수 있다❗
예)
@DeleteMapping("/{id}")
public String deleteSchedule(@PathVariable Long id) {
scheduleList.remove(id); // remove 함수 사용
return "일정 삭제 완료";
}
예시 코드에서 구조를 설명했을 때,
접근 제어자 + return 타입 + 메서드명 + () 안에 매개변수
매개변수가 있다면 () 안에 넣어주고, 없다면 비워둔다
만약에 void를 넣어서 수정할 경우,
@DeleteMapping("/{id}")
public void deleteSchedule(@PathVariable Long id) {
scheduleList.remove(id); // remove 함수 사용
}
void 는 반환 값 없이 메서드를 종료하겠다는 뜻이기 때문에, return 문이 없어져야 한다