--오전 수업내용--
1. 생성자 예제코드 - 리뷰
201 - 202p, 205p
2. 상속 예제코드 - 리뷰
219 - 220p
https://dwc04112.tistory.com/16?category=1003212
3. 인터페이스 예제코드
274 - 275p
https://dwc04112.tistory.com/17?category=1003212
* 객체의 이름 class의 이름을 바꾸고싶을때 : 바꿀 객체,class를 우클릭 refactor - rename
0811 오후 수업내용
3-1. 오전의 인터페이스 예제코드 리뷰
4. Java DB 회사원 코드 수정
1. 범위값 a에서부터 b값을 받는다
2. 여기서 a값이 b 보다 크면 오류메시지와 함께 다시 1번으로 돌아간다
3. 범위가 맞으면 지정한 범위값을 print후 범위에 맞는 회사원 출력
4. 스캔코드는 inputUtill에서 받아오고 비교하는 부분도 받아오고싶었지만
a와b 두개의 값을 retrun하지 못해서 실패..
5. LocalDate, LocalTime, LocalDateTime 정리
====== LocalDate, LocalTime, LocalDateTime 정리=====
//날짜를 직접 지정
LocalDate targetDate = LocalDate.of(2021,8,30);
System.out.println(targetDate);
//현재 시간 출력
// 로컬 컴퓨터의 현재 시간 정보를 저장한 LocalDate 객체를 리턴.
LocalTime currentTime = LocalTime.now();
System.out.println(currentTime);
//시간을 직접 지정
LocalTime targetTime = LocalTime.of(12,33,35,12); //0.000000012
System.out.println(targetTime);
//현재 날짜 & 시간
LocalDateTime currentDateTime = LocalDateTime.now();
System.out.println(currentDateTime);
//날짜 &시간 직접 지정
LocalDateTime targetDateTime = LocalDateTime.of(2021,8,11,16,23,33,222);
System.out.println(targetDateTime);
//String date (dbms에서 가져온 값)을 LocalDateTime으로 바꾸려면?
String date="2021-08-11";
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//위의 date랑 dateTimeFormatter를 아래에 집어넣음. 패턴은 yyyy-MM-dd
LocalDate parsedDate = LocalDate.parse(date,dateTimeFormatter);
System.out.println(parsedDate);
String date2 = "2021-08-11T16:41:31.087";
LocalDateTime parsedLocalDateTime = LocalDateTime.parse(date2);
System.out.println("parsedLocalDateTime = " + parsedLocalDateTime);
System.out.println("=================================================");
//날짜 더하기 빼기
LocalDateTime currentDateTimePlus = LocalDateTime.now();
currentDateTimePlus = currentDateTimePlus.plusDays(2);
System.out.println(currentDateTimePlus);
System.out.println(currentDateTimePlus.minusDays(2));
//날짜 비교예제
LocalDateTime startDateTime = LocalDateTime.now();
LocalDateTime endDateTime = LocalDateTime.of(2021,9,11,5,33,50);
startDateTime.isBefore(endDateTime); //startDate 가 endDate 보다 이전 날짜인지 비교
startDateTime.isEqual(endDateTime); //동일 날짜인지
startDateTime.isAfter(endDateTime); //이후날짜인지
System.out.println(startDateTime.isAfter(endDateTime));
System.out.println("====================날짜 포맷===================");
//날짜 포맷
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy년 M월 d일 a h시 m분");
String nowstring = now.format(dateTimeFormatter1);
System.out.println(nowstring); //결과 : 2021년 8월 오후 5시 32분
LocalDateTime now2 = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
String now2string = now.format(dateTimeFormatter2);
System.out.println(now2string); //결과 : 2021-08-11 05:35:04
System.out.println("=================================================");
//날짜 변환
//LocalDate > String
LocalDate.of(2021, 12, 12).format(DateTimeFormatter.BASIC_ISO_DATE);
//String > LocalDate
LocalDate.parse("2021-12-27");
LocalDate.parse("20211227", DateTimeFormatter.BASIC_ISO_DATE);
System.out.println(LocalDate.parse("2021-12-27"));
System.out.println("여기까지 LocalDate String 변환");
//LocalDateTime > String
//LocalDate > String 처럼 변환하면 일 까지 출력되더라
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//LocalDate > java.sql.Date
date.valueOf(LocalDate.of(2021,12,27));
//출력해봄
System.out.println(date.valueOf(LocalDate.of(2021,12,27)));
Java ExtendsPractice(상속예제 0811)
=====================상속 예제====================== //p219 ~ 220 public class Main { public static void main(String[] arg){ Salesman2 sales2 = new Salesman2("오정원", "영업부", 100000000,70000000);..
dwc04112.tistory.com
앞으로 이 폼을 유지하면서 배운내용 밑에 코드&설명 링크를 붙일예정!
이렇게 써야 다시볼때 편할 것 같아서
'수업 & 공부 > 수업 내용' 카테고리의 다른 글
9- 파일IO (Input Output) 예제 / 정리 (0) | 2021.08.13 |
---|---|
8- Intellij IDEA환경 서블릿 구동 (0) | 2021.08.12 |
6- java예제(코드) 와 db연동(회사원) (0) | 2021.08.10 |
5- java와 DB연동 (회사원) (0) | 2021.08.09 |
4- Java 와 DB 연동1 (0805) (0) | 2021.08.05 |