날아라김지원
JAVA 생성자(Constructor)
JAVA, Spring 2023. 4. 4. 17:57

- 생성자(Constructor) 생성자를 사용하면 객체변수에 무조건 값을 설정해야 객체가 생성되게 만들 수 있다. 아래와같은 코드를 그 아래코드와 같이 바꾸면 된다. class HouseDog extends Dog { void sleep() { System.out.println(this.name + " zzz in house"); } void sleep(int hour) { System.out.println(this.name + " zzz in house for " + hour + " hours"); } } class HouseDog extends Dog { HouseDog(String name) { this.setName(name); } void sleep() { System.out.println(t..

JAVA Call by value, 클래스 상속(Inheritance)
JAVA, Spring 2023. 4. 4. 16:37

- JAVA Call by value class Updater { void update(int count) { count++; } } class Counter { int count = 0; // 객체변수 } public class Sample { public static void main(String[] args) { Counter myCounter = new Counter(); System.out.println("before update:"+myCounter.count); Updater myUpdater = new Updater(); myUpdater.update(myCounter.count); System.out.println("after update:"+myCounter.count); } } 위와같..

article thumbnail
JAVA 클래스(class) 와 메서드(method)
JAVA, Spring 2023. 4. 4. 15:30

- 클래스(class) 클래스를 보통 설명할때 찍어낸다고 많이 표현한다. class FishBread { } public class Sample { public static void main(String[] args) { } } 이러한 클래스의 가장 중요한 기능은 객체(object)를 만드는 기능이다. class FishBread { } public class Sample { public static void main(String[] args) { FishBread fish1 = new FishBread(); } } new 는 객체 생성키워드이고, FishBread클래스의 인스턴스 (instance) fish1을 만들 수 있다. fish1은 FishBread의 객체이다. 객체와 인스턴스는 용어의 차이라고..

article thumbnail
Spring Boot CRUD만들어보기 (데이터생성 JPA, DB로저장)
JAVA, Spring 2023. 4. 3. 21:58

- 클라이언트 -> 서버 -> 데이터베이스로 저장 데이터를 DTO객체 컨트롤러도 받는것까지 진행 했다. 이 내용을 DB에 저장해보자 서버(JAVA) -> Database (SQL) 을 연결해야 하는데 이 도구가 JPA다 - JPA 자바 ORM 이다. 즉 컨트롤러의 DTO를 테이블과 매핑시킨다. Entity와Repository를 통해 Database로 자료를 넘겨 저장해준다. Entity : 자바객체를 DB가 이해할 수 있게 규격화된 데이터 Repository: 이 데이터를 Database로 넘겨주는 기능을 한다. 아래코드와 출력문을 보면 이렇게 이해할 수 있다. 1.form데이터로 날라온걸 우선 DTO객체로 받는다 2.그리고 컨트롤러에 있는걸 다시 Entity로 바꾼다. 3.마지막으로 Repository..

article thumbnail
Spring Boot CRUD만들어보기 (form, dto, controller 설정)
JAVA, Spring 2023. 4. 3. 21:23

- form태그 어디로 ,어떻게 보내야 할지 적어줘야한다. 이 from태그를 받는 객체는 DTO라고한다. 클라이언트 -> 서버로 전달하는데 그리고 DTO객체를 새로운 컨트롤러로 조작한다. action과 method 부분이 전송에 중요한 부분이다. 각각 어디로, 어떻게 보내는지 부분이다. {{>layouts/header}}} subject content Submit {{>layouts/footer}}} - 폼 데이터 받기 package com.example.first.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.spr..

article thumbnail
JAVA 객체지향 프로그래밍에 대한 이해
JAVA, Spring 2023. 4. 3. 17:57

- 자바 객체지향 단순하게 설명한거긴 하지만 계산기를 이용한 예제가 아주 쉽게 이해하는데 도움이 되었다. class Calculator { static int result = 0; static int add(int num) { result += num; return result; } } public class Sample { public static void main(String[] args) { System.out.println(Calculator.add(3)); System.out.println(Calculator.add(4)); } } 결과는 3과 7이나온다. 객체로 선언된 result에 값이 계속 더해지기 때문이다. 근데 만약 계산기가 한번 더 필요한 상황이 나온다면? 저 클래스를 하나 또 만들것..

article thumbnail
Spring Boot MVC의 역할과 실행 흐름 , 템플릿제작
JAVA, Spring 2023. 4. 2. 20:52

- MVC의 역할 1)컨트롤러 서버에서 요청은 컨트롤러가 받는다. @GetMapping 어노테이션을 통해 package com.example.first.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public class FirstController { @GetMapping("/hi") public String niceToMeetYou(Model model){ model.addAttribute("username","kimjiwon"); return "..

article thumbnail
Spring Boot 뷰 템플릿과 MVC패턴
JAVA, Spring 2023. 4. 2. 19:34

-MVC 패턴 1)Model(data) 아래 코드중 Model이란 객체로 생성한 부분이 데이터가 있는 부분이다. Firstcontoller.java package com.example.first.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public class FirstController { @GetMapping("/hi") public String niceToMeetYou(Model model){ model.addAttribute("usernam..