###개념 - 트랜지션

float 고정 기능 공식
float요소의 부모에 주면 해결된다 -라이브러리-
.row::after{
content:"";
clear:both;
display:block;
}

###flex 익히기

플렉스는 자식한테만 영향을 줌
자기 x 자손 x

플렉스 명령어들

```
justify-content - Flex 요소들을 가로선 상에서 정렬합니다.

> flex-start (default) flex-end center space-between space-around space-evenly

align-items - Flex 요소를 세로선 상에서 정렬합니다.

> flex-start flex-end center baseline stretch (default)

flex-direction - 정렬할 방향을 지정합니다. 행 , 열

> row (default) row-reverse column column-reverse

order - Flex 요소의 순서를 지정합니다.

> <integer> (... -1, 0 (default), 1, ...)

align-self -지정된 align-items 값을 무시하고 Flex 요소를 세로선 상에서 정렬합니다.

> flex-start flex-end center baseline stretch

flex-wrap - Flex 요소들을 한 줄 또는 여러 줄에 걸쳐 정렬합니다

> flex-start flex-end center baseline stretch

flex-flow -

> 다음의 속성들을 간략히 한 속성입니다: flex-direction and flex-wrap.

<flex-direction> <flex-wrap>

align-content - 세로선 상에 여분의 공간이 있는 경우 Flex 컨테이너 사이의 간격을 조절합니다.

> flex-start flex-end center space-between space-around space-evenly stretch (default)
```

fontawesome -> 아이콘즈

 

https://flexboxfroggy.com/#ko 개구리 flex 연습 사이트 직관적이다.

 

https://codepen.io/enxaneta/pen/adLPwv flex 적용해보기

###개념 - 개념 : position 속성 정리

 ###개념 - 개념 - top, left, right, bottom 

###개념 - 개념 : z-index 예제 

###개념 - 개념 : white-space:nowrap, 줄바꿈 금지

 ###개념 - 개념 : overflow-x:auto, 스크롤바 자동생성 

###개념 - 개념 : overflow-x:scroll, 스크롤바 무조건 생성 

###개념 - 개념 : overflow-x:hidden, 넘치는 내용 숨김

 ###개념 - 개념 : text-overflow:ellipsis, 넘쳐서 숨겨지는 텍스트 ... 처리(5분완성)

-이미지-

section{
width: 400px;
border:10px solid red;
}
section > img {
display:block;
width: 100%; //부모의 너비 기준에 변화

}

position은 static이 기본값 겹치지 않는다 ->사람
absolute 하면 겹쳐짐,독립적인 무언가. top left로 좌표이동 ->유령

부모에게 position:relative;를 주면
부모의 범위를 벗어나지 못한다

body,ul,li 노말라이징 -패딩 0 마진 0 리스트스타일 논

TODO

<h1>완료 : 메뉴아이템에 마우스를 올렸을 때 자식인 텍스트(a)의 배경색과 글자색을 적절하게 변경해주세요.</h1>
<h1>요구 : -</h1>

<nav class="menu-1">
  <ul>
    <li><a href="#">메뉴아이템1</a></li>
    <li><a href="#">메뉴아이템2</a></li>
    <li><a href="#">메뉴아이템3</a></li>
  </ul>
</nav>

/* css 부분 */

/* 노말라이즈 => 모든 작업 전에 한번 */
/* 노말라이즈 */
ul, li {
  /* margin을 없앤다. */
  margin:0;
  padding:0;
  list-style:none;
}

/* a를 노말라이즈 합니다. */
a {
  /* 이렇게 하면 나중에 문제가 됩니다. */
  /* inherit => 나는 개성이 없어요. => 나는 부모의 속성을 그대로 물려받겠습니다. */
  color:inherit;
  text-decoration:none;
}

.menu-1 {
  text-align:center;
}

.menu-1 > ul {
  background-color:#dfdfdf;
  display:inline-block;
  padding:0 10px;
  border-radius:5px;
}

.menu-1 > ul > li {
  display:inline-block;
  width:200px;
}

.menu-1 > ul > li > a {
  padding:10px;
  /* display:inline 요소에는 margin, padding, width, height가 일반적인 방식으로 적용되지 않는다. */
  display:block;
}

/* 마우스가 올려진 메뉴아이템의 자식인 a */
.menu-1 > ul > li:hover > a {
  color:white;
  background-color:black;
}


a 노말라이징 -텍스트 데코 논 -컬러 인헤릿

1차메뉴 작성
-.menu-1 ul
백그라운드 컬러
-.menu-1 > ul
디스플레이 인라인블럭
패딩 0 20px
곡률 5px

-.menu-1 ul > li:hover > a
백그라운드 컬러
컬러

2-2차 메뉴 나오게하기
-2차메뉴 정렬 탑,레프트,위드 포지션
-2차메뉴 가두기
-2차메뉴 유령화

3-3차 메뉴 나오게 하기
-3차메뉴 구별짓기
-3차메뉴 옆에 나오기
-3차메뉴 마지막꺼 왼쪽에 나오기

 

 

package com.KoreaIT.java.AM;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static List<Article> articles = new ArrayList<>();

	public static void main(String[] args) {
		System.out.println("==프로그램 시작==");

		makeTestData();

		Scanner sc = new Scanner(System.in);

		int lastArticleId = 3;

		while (true) {

			System.out.print("명령어 > ");
			String command = sc.nextLine().trim();

			if (command.length() == 0) {
				System.out.println("명령어를 입력해주세요");
				continue;
			}

			if (command.equals("exit")) {
				break;
			}

			if (command.equals("article list")) {
				if (articles.size() == 0) {
					System.out.println("게시글이 없습니다");
				} else {
					System.out.println(" 번호  //  제목    //  조회  ");
					for (int i = articles.size() - 1; i >= 0; i--) {
						Article article = articles.get(i);
						System.out.printf("  %d   //   %s   //   %d  \n", article.id, article.title, article.hit);
					}
				}

			} else if (command.equals("article write")) {
				int id = lastArticleId + 1;
				System.out.print("제목 : ");
				String regDate = Util.getNowDateTimeStr();
				String title = sc.nextLine();
				System.out.print("내용 : ");
				String body = sc.nextLine();

				Article article = new Article(id, regDate, regDate, title, body);
				articles.add(article);

				System.out.printf("%d번글이 생성되었습니다\n", id);
				lastArticleId++;

			} else if (command.startsWith("article detail")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				Article foundArticle = getArticleById(id);

				if (foundArticle == null) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}

				foundArticle.hit++;

				System.out.println("번호 : " + foundArticle.id);
				System.out.println("작성날짜 : " + foundArticle.regDate);
				System.out.println("수정날짜 : " + foundArticle.updateDate);
				System.out.println("제목 : " + foundArticle.title);
				System.out.println("내용 : " + foundArticle.body);
				System.out.println("조회 : " + foundArticle.hit);

			} else if (command.startsWith("article modify")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				Article foundArticle = getArticleById(id);

				if (foundArticle == null) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}
				System.out.print("새 제목 : ");
				String updateDate = Util.getNowDateTimeStr();
				String newTitle = sc.nextLine();
				System.out.print("새 내용 : ");
				String newBody = sc.nextLine();

				foundArticle.title = newTitle;
				foundArticle.body = newBody;
				foundArticle.updateDate = updateDate;

				System.out.println(id + "번 글을 수정했습니다");

			} else if (command.startsWith("article delete")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				int foundIndex = getArticleIndexById(id);

				if (foundIndex == -1) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}

				articles.remove(foundIndex);
				System.out.println(id + "번 글을 삭제했습니다");

			} else {
				System.out.println("존재하지 않는 명령어입니다");
			}
		}

		System.out.println("==프로그램 끝==");

		sc.close();
	}

	private static int getArticleIndexById(int id) {
		int i = 0;
		for (Article article : articles) {
			if (article.id == id) {
				return i;
			}
			i++;
		}
		return -1;
	}

	private static Article getArticleById(int id) {
//		for (int i = 0; i < articles.size(); i++) {
//			Article article = articles.get(i);
//			if (article.id == id) {
//				return article;
//			}
//		}

//		for (Article article : articles) {
//			if (article.id == id) {
//				return article;
//			}
//		}
		int index = getArticleIndexById(id);

		if (index != -1) {
			return articles.get(index);
		}

		return null;
	}

	private static void makeTestData() {
		System.out.println("테스트를 위한 데이터를 생성합니다");
		articles.add(new Article(1, Util.getNowDateTimeStr(), Util.getNowDateTimeStr(), "제목1", "제목1", 11));
		articles.add(new Article(2, Util.getNowDateTimeStr(), Util.getNowDateTimeStr(), "제목2", "제목2", 22));
		articles.add(new Article(3, Util.getNowDateTimeStr(), Util.getNowDateTimeStr(), "제목3", "제목3", 33));
	}
}

class Article {
	int id;
	String regDate;
	String updateDate;
	String title;
	String body;
	int hit;

	Article(int id, String regDate, String updateDate, String title, String body) {
		this(id, regDate, updateDate, title, body, 0);
	}

	Article(int id, String regDate, String updateDate, String title, String body, int hit) {
		this.id = id;
		this.regDate = regDate;
		this.updateDate = updateDate;
		this.title = title;
		this.body = body;
		this.hit = hit;
	}
}
package java_exam;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
//자바에 존재하는 클래스, 메소드의 기능을 이렇게 다른 클래스에서 사용하려 하는 경우
//import라는 명령어를 이용해 연결해줍니다

public class Main {

	static List<Article> articles = new ArrayList<>();
	// 메인 클래스와 메서드 사이에 리스트를 만드는 것은
	// 메인 메서드 외에 다른 클래스에도 접근하기 위함입니다
	// static을 붙여 클래스 변수라는걸 나타냅니다
	//해당 클래스의 모든 인스턴스들이 공유하는 변수입니다 다른 메서드에서도 해당 리스트에 접근을 가능하게 합니다.
	//List와 ArrayList는 자바에서 제공하는 기능있는 클래스 이므로 import 합니다
	//List는 자바 자체에서 제공하는 인터페이스 중 하나로, 여러 개의 요소들을 순서에 따라 저장하고 관리할 수 있습니다.
    //List 인터페이스를 구현한 ArrayList 클래스를 이용하여, Article 객체들을 담을 수 있는 리스트를 생성하였습니다. 생성된 리스트의 이름은 articles이며
	//리스트 내부에는 Article 객체들이 담길 수 있습니다.
	//해당 ArrayList는 Article 타입의 변수 articles의 정보를 담기위해 시행하며
	//DB 대용으로 해당 프로젝트에서 저장값을 위해 쓰이는 중입니다
	public static void main(String[] args) {

		System.out.println("==프로그램 시작==");// 메인 메서드에서 가장 먼저 실행 될 출력문.
		makeTestData(); // makeTestData라는 함수를 실행 시킵니다 메인 메서드 안쪽에 만들었기에 Main.makeTestDate(); Main을 생략해도 됍니다

		Scanner sc = new Scanner(System.in);//출력문을 콘솔에 나타내기 위해
		 //스캐너 객체를 만들고 sc라는 변수에 담습니다 입력받을 대상은 표준입력 (System.in) 입니다
		 //스캐너 클래스는 자바에서 제공하기에 import 합니다

		int lastArticleId = 3;//글의 갯수를 저장하기 위한 정수 변수 초기화입니다
		//반복문 밖에 만든 이유는 반복문에서 계속 초기화 돼 값이 입력되지 않기 때문엡니다
		//3으로 하는 이유는 테스트 데이터를 3개 만들어서 3개를 기본값으로 가정하고 시작합니다.

		while (true) { // 명령어를 실행 하기 위한 무한 반복문의 시작

			System.out.print("명령어 > ");
			String command = sc.nextLine().trim(); //문자열 변수 command는
			//스캐너 변수 sc의 기능 nextLine()과 trim을 저장합니다

			if (command.length() == 0) {// 입력한 글자가 0이면 (없으면)
				System.out.println("명령어를 입력해주세요");//이것을 출력
				continue;//반복문으로 돌아갑니다 
			}

			if (command.equals("exit")) {//입력한 글자가 exit와 같다면
				break;//반복문을 빠져나갑니다
			}

			if (command.equals("article list")) {//입력한 글자가 article list라면
				if (articles.size() == 0) {//배열에 담겨둔 articles에서 저장해둔게 0이라면
					System.out.println("게시글이 없습니다");//출력
				} else {//그게 아니면 게시글 있다는것이니
					System.out.println(" 번호  //  제목    //  조회  ");//출력
					for (int i = articles.size() - 1; i >= 0; i--) {//i를 articles 길이의 배열 변수로 -1을 한 뒤 초기화합니다.조건식은 i가0이상일때이며 ,증감식은 i를 1씩 줄여갑니다
						Article article = articles.get(i);//Article 타입의 변수 article에는 artcles의 기능을 받습니다
						System.out.printf("  %d   //   %s   //   %d  \n", article.id, article.title, article.hit);
					}//그 결과 article.id,article.title,article.hit에 저장된 값을 %d(정수형) %s(문자형)으로 출력하고 \n 줄바꿈 합니다
				}

			} else if (command.equals("article write")) {//article list가 아닌 article write를 입력한다면
				int id = lastArticleId + 1; //id를 lastAtricleId(글번호) 0번부터가 아닌 1번부터 하기에 1을 더 한 값을 초기화시키고
				System.out.print("제목 : "); //제목 : 출력
				String regDate = Util.getNowDateTimeStr();//제목에 regDate(시점)이 담깁니다
				String title = sc.nextLine();//title이란 문자열 변수엔 선언해둔 스크린 변수sc의 nextLine();기능을 담습니다
				System.out.print("내용 : ");
				String body = sc.nextLine();//body이란 문자열 변수엔 선언해둔 스크린 변수sc의 nextLine();기능을 담습니다

				Article article = new Article(id, regDate, regDate, title, body);
				//Article 타입 article이란 변수에 객체 Article클래스를 담습니다 클래스 생성자 첫번째의 기능을 담습니다
				articles.add(article);
				//ArrayList클래스의 객체인 articles에 article이란 객체를 추가하는 작업입니다
				//article write에 쓰인 값들을 ArrayList에 저장하기 위함입니다

				System.out.printf("%d번글이 생성되었습니다\n", id);
			    //id 값에 담긴 %d(정수형)으로 출력하고 줄 바꿈
				lastArticleId++;//lastArticleId라는 변수를 1 추가합니다
				//반복문을 빠져 나갔을때 메인 메서드 밖에 지정해놓은 int 변수에 저장됍니다

			} else if (command.startsWith("article detail")) {//article list가 아닌 article detail을 입력한다면 실행
				//startWith 기능은 ~로 시작하는 단어를 찾는 명령어로
				//해당 article detail 로 시작하는 명령어를 받습니다

				String[] cmdDiv = command.split(" ");
				//문자열 배열에 cmdDiv라는 변수를 지정하고 split(" ") 기능을 넣습니다
				//공백을 기준으로 나눠서 인식하겠단 의미입니다

				if (cmdDiv.length < 3) {//그렇게 공백으로 검산해본 값이 3미만이면 ->article detail 후 입력된게 없음
					System.out.println("명령어를 확인해주세요");//출력
					continue;//해당 반복문을 돌아갑니다
				}

				int id = Integer.parseInt(cmdDiv[2]);
				//int id값을 문자열 배열 cmdDiv[2]값으로 치환하겠단 소리입니다
				//ㅁ ㅁ ㅁ  세번째 ㅁ에 숫자가 들어와도 문자로 인식하겠단 소리입니다

				Article foundArticle = getArticleById(id);
				//Article 타입의 변수 foundArticle에 getArticleById의 메소드 id값을 넣습니다

				if (foundArticle == null) {//found값이 null이라면
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);//id값이 없다 출력하고
					continue;//해당 반복문으로 돌아갑니다
				}

				foundArticle.hit++;
				//detail 기능을 할 때마다 조회수가 1씩 증가하도록 합니다

				System.out.println("번호 : " + foundArticle.id);
				System.out.println("작성날짜 : " + foundArticle.regDate);
				System.out.println("수정날짜 : " + foundArticle.updateDate);
				System.out.println("제목 : " + foundArticle.title);
				System.out.println("내용 : " + foundArticle.body);
				System.out.println("조회 : " + foundArticle.hit);
				//여기까지 걸리지 않고 내려왔다면 실행
                //foundArticle.[  ]  찾은 값들을 넣어 출력해줍니다
			} else if (command.startsWith("article modify")) {//article list가 아닌 article modify을 입력한다면 실행

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				Article foundArticle = getArticleById(id);

				if (foundArticle == null) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}//detail과 같은 이유
				
				//여기까지 걸리지 않고 내려왔다면 실행
				System.out.print("새 제목 : ");
				String updateDate = Util.getNowDateTimeStr();
				String newTitle = sc.nextLine();
				System.out.print("새 내용 : ");
				String newBody = sc.nextLine();

				foundArticle.title = newTitle;
				foundArticle.body = newBody;
				foundArticle.updateDate = updateDate;

				System.out.println(id + "번 글을 수정했습니다");

			} else if (command.startsWith("article delete")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				int foundIndex = getArticleIndexById(id);
				//int타입 foundIndex변수에 getArticleIndexById의 메소드 id값을 넣겠다

				if (foundIndex == -1) {//foundIndex의 값이 -1이라면 존재하지 않으므로
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);//출력
					continue;//해당 반복문으로 돌아갑니다
				}//detail과 같은 이유

				articles.remove(foundIndex);//여기까지 걸리지 않고 내려왔다면 실행
				System.out.println(id + "번 글을 삭제했습니다");

			} else {//처음 if문과 이어지는 조건문 else
				System.out.println("존재하지 않는 명령어입니다");
			}//여기까지 왔다면 지정해놓은 모든 명령어가 없다는것
		}

		System.out.println("==프로그램 끝==");//exit로 해당 클래스를 break했을때 출력

		sc.close();//스캐너의 기능의 종료  습관화 들이면 좋습니다
	}

	private static int getArticleIndexById(int id) {
		int i = 0;
		for (Article article : articles) {
			if (article.id == id) {
				return i;
			}
			i++;
		}
		return -1;
	}
	
//	이 코드는 id 값에 해당하는 게시물의 인덱스를 찾아주는 메소드입니다.
//	articles는 게시물 정보를 담고 있는 List<Article> 객체로 
//for-each 반복문을 사용하여 모든 게시물을 순차적으로 조회하면서 article.id와 id 값을 비교합니다. 만약 두 값이 일치한다면
//return i를 통해 해당 게시물의 인덱스 i를 반환합니다.	
//	모든 게시물을 조회해도 해당 id 값에 해당하는 게시물을 찾지 못했다면
//return -1을 통해 id 값에 해당하는 게시물이 없음을 나타냅니다.	
//	따라서 이 메소드를 호출하면 id 값에 해당하는 게시물이 존재하는 경우 해당 게시물의 인덱스를 반환하고 존재하지 않는 경우 -1을 반환하게 됩니다.

	private static Article getArticleById(int id) {
		
//		for (int i = 0; i < articles.size(); i++) { 위의 메서드들이 없다면 글의 유무를 판별 할 때 마다
//			Article article = articles.get(i);     이렇게 매번 articles.size의 배열을
//			if (article.id == id) {                일일히 찾아봐야 하므로
//				return article;                     중복값 제거 메서드를 만듭니다
//			}
//		}

//		for (Article article : articles) {
//			if (article.id == id) {
//				return article;
//			}
//		}
		int index = getArticleIndexById(id);

		if (index != -1) {
			return articles.get(index);
		}

		return null;
	}
	
//	이 코드는 id 값에 해당하는 게시물 객체(Article)를 반환하는 메소드입니다.
//	getArticleIndexById 메소드를 호출하여 id 값에 해당하는 게시물의 인덱스를 구하고
//  이 인덱스를 index 변수에 저장합니다
//	index 변수의 값이 -1이 아니라면, articles 리스트에서 
//  index 인덱스에 해당하는 게시물 객체를 return articles.get(index);를 통해 반환합니다
//	근데 index 값이 -1이라면, 해당 id 값에 해당하는 게시물이 존재하지 않는 것이므로 null 값을 반환합니다.
//	따라서 이 메소드를 호출하면 id 값에 해당하는 게시물이 존재하는 경우 해당 게시물 객체를 반환하고 존재하지 않는 경우 null을 반환하게 됩니다.





	
	
	
	
	private static void makeTestData() { // 메인 메서드에 만들어 놓았던 테스트 데이터를 출력하는 메서드
		System.out.println("테스트를 위한 데이터를 생성합니다");
		articles.add(new Article(1, Util.getNowDateTimeStr(), Util.getNowDateTimeStr(), "제목1", "제목1", 11));
		articles.add(new Article(2, Util.getNowDateTimeStr(), Util.getNowDateTimeStr(), "제목2", "제목2", 22));
		articles.add(new Article(3, Util.getNowDateTimeStr(), Util.getNowDateTimeStr(), "제목3", "제목3", 33));
	} //articles 에 저장된 값들을 출력합니다 이때,2번째 생성자가 쓰입니다
}

class Article { // new를 했으니 Article 객체를 만들어줍니다.
	int id;
	String regDate;
	String updateDate;
	String title;
	String body;
	int hit;

	Article(int id, String regDate, String updateDate, String title, String body) {
		this(id, regDate, updateDate, title, body, 0);
	}// 생성자를 만들어 객체를 생성하자 마자 값을 넣어줍니다

	Article(int id, String regDate, String updateDate, String title, String body, int hit) {
		this.id = id;
		this.regDate = regDate;
		this.updateDate = updateDate;
		this.title = title;
		this.body = body;
		this.hit = hit;
	}// 두번째 생성자 입니다 클래스 이름과 똑같이 만들며 위의 생성자와도 이름이 같습니다
		// 하지만 같은 생성자를 만들 때는 메서드의 인자나 타입이 달라야하는데 이것을 오버로딩 과정이라고 합니다.
}
package com.KoreaIT.java.AM;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		System.out.println("==프로그램 시작==");

		Scanner sc = new Scanner(System.in);

		int lastArticleId = 0;
		List<Article> articles = new ArrayList<>();

		while (true) {

			System.out.print("명령어 > ");
			String command = sc.nextLine().trim();

			if (command.length() == 0) {
				System.out.println("명령어를 입력해주세요");
				continue;
			}

			if (command.equals("exit")) {
				break;
			}

			if (command.equals("article list")) {
				if (articles.size() == 0) {
					System.out.println("게시글이 없습니다");
				} else {
					System.out.println(" 번호  //  제목    //  조회  ");
					for (int i = articles.size() - 1; i >= 0; i--) {
						Article article = articles.get(i);
						System.out.printf("  %d   //   %s   //   %d  \n", article.id, article.title, article.hit);
					}
				}

			} else if (command.equals("article write")) {
				int id = lastArticleId + 1;
				System.out.print("제목 : ");
				String regDate = Util.getNowDateTimeStr();
				String title = sc.nextLine();
				System.out.print("내용 : ");
				String body = sc.nextLine();

				Article article = new Article(id, regDate, regDate, title, body);
				articles.add(article);

				System.out.printf("%d번글이 생성되었습니다\n", id);
				lastArticleId++;

			} else if (command.startsWith("article detail")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				Article foundArticle = null;

				for (int i = 0; i < articles.size(); i++) {
					Article article = articles.get(i);
					if (article.id == id) {
						foundArticle = article;
						break;
					}
				}

				if (foundArticle == null) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}

				foundArticle.hit++;

				System.out.println("번호 : " + foundArticle.id);
				System.out.println("작성날짜 : " + foundArticle.regDate);
				System.out.println("수정날짜 : " + foundArticle.updateDate);
				System.out.println("제목 : " + foundArticle.title);
				System.out.println("내용 : " + foundArticle.body);
				System.out.println("조회 : " + foundArticle.hit);

			} else if (command.startsWith("article modify")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				Article foundArticle = null;

				for (int i = 0; i < articles.size(); i++) {
					Article article = articles.get(i);
					if (article.id == id) {
						foundArticle = article;
						break;
					}
				}

				if (foundArticle == null) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}
				System.out.print("새 제목 : ");
				String updateDate = Util.getNowDateTimeStr();
				String newTitle = sc.nextLine();
				System.out.print("새 내용 : ");
				String newBody = sc.nextLine();

				foundArticle.title = newTitle;
				foundArticle.body = newBody;
				foundArticle.updateDate = updateDate;

				System.out.println(id + "번 글을 수정했습니다");

			} else if (command.startsWith("article delete")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				int foundIndex = -1;
				for (int i = 0; i < articles.size(); i++) {
					Article article = articles.get(i);
					if (article.id == id) {
						foundIndex = i;
						break;
					}
				}

				if (foundIndex == -1) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}

				articles.remove(foundIndex);
				System.out.println(id + "번 글을 삭제했습니다");

			} else {
				System.out.println("존재하지 않는 명령어입니다");
			}
		}

		System.out.println("==프로그램 끝==");

		sc.close();
	}
}

class Article {
	int id;
	String regDate;
	String updateDate;
	String title;
	String body;
	int hit;

	Article(int id, String regDate, String updateDate, String title, String body) {
		this.id = id;
		this.regDate = regDate;
		this.updateDate = updateDate;
		this.title = title;
		this.body = body;
		this.hit = 0;
	}
}
package com.KoreaIT.java.AM;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		System.out.println("==프로그램 시작==");

		Scanner sc = new Scanner(System.in);

		int lastArticleId = 0;
		List<Article> articles = new ArrayList<>();

		while (true) {

			System.out.print("명령어 > ");
			String command = sc.nextLine().trim();

			if (command.length() == 0) {
				System.out.println("명령어를 입력해주세요");
				continue;
			}

			if (command.equals("exit")) {
				break;
			}

			if (command.equals("article list")) {
				if (articles.size() == 0) {
					System.out.println("게시글이 없습니다");
				} else {
					System.out.println(" 번호  //  제목  ");
					for (int i = articles.size() - 1; i >= 0; i--) {
						Article article = articles.get(i);
						System.out.printf("  %d   //   %s  \n", article.id, article.title);
					}
				}

			} else if (command.equals("article write")) {
				int id = lastArticleId + 1;
				System.out.print("제목 : ");
				String regDate = Util.getNowDateTimeStr();
				String title = sc.nextLine();
				System.out.print("내용 : ");
				String body = sc.nextLine();

				Article article = new Article(id, regDate, title, body);
				articles.add(article);

				System.out.printf("%d번글이 생성되었습니다\n", id);
				lastArticleId++;

			} else if (command.startsWith("article detail")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				Article foundArticle = null;

				for (int i = 0; i < articles.size(); i++) {
					Article article = articles.get(i);
					if (article.id == id) {
						foundArticle = article;
						break;
					}
				}

				if (foundArticle == null) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}
				System.out.println("번호 : " + foundArticle.id);
				System.out.println("날짜 : " + foundArticle.regDate);
				System.out.println("제목 : " + foundArticle.title);
				System.out.println("내용 : " + foundArticle.body);

			} else if (command.startsWith("article delete")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				int foundIndex = -1;
				for (int i = 0; i < articles.size(); i++) {
					Article article = articles.get(i);
					if (article.id == id) {
						foundIndex = i;
						break;
					}
				}

				if (foundIndex == -1) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}

				articles.remove(foundIndex);
				System.out.println(id + "번 글을 삭제했습니다");

			} else {
				System.out.println("존재하지 않는 명령어입니다");
			}
		}

		System.out.println("==프로그램 끝==");

		sc.close();
	}
}

class Article {
	int id;
	String regDate;
	String title;
	String body;

	Article(int id, String regDate, String title, String body) {
		this.id = id;
		this.regDate = regDate;
		this.title = title;
		this.body = body;
	}
}
package com.KoreaIT.java.AM;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		System.out.println("==프로그램 시작==");

		Scanner sc = new Scanner(System.in);

		int lastArticleId = 0;
		List<Article> articles = new ArrayList<>();

		while (true) {

			System.out.print("명령어 > ");
			String command = sc.nextLine().trim();

			if (command.length() == 0) {
				System.out.println("명령어를 입력해주세요");
				continue;
			}

			if (command.equals("exit")) {
				break;
			}

			if (command.equals("article list")) {
				if (articles.size() == 0) {
					System.out.println("게시글이 없습니다");
				} else {
					System.out.println(" 번호  //  제목  ");
					for (int i = articles.size() - 1; i >= 0; i--) {
						Article article = articles.get(i);
						System.out.printf("  %d   //   %s  \n", article.id, article.title);
					}
				}

			} else if (command.equals("article write")) {
				int id = lastArticleId + 1;
				System.out.print("제목 : ");
				String regDate = Util.getNowDateTimeStr();
				String title = sc.nextLine();
				System.out.print("내용 : ");
				String body = sc.nextLine();

				Article article = new Article(id, regDate, title, body);
				articles.add(article);

				System.out.printf("%d번글이 생성되었습니다\n", id);
				lastArticleId++;

			} else if (command.startsWith("article detail")) {

				String[] cmdDiv = command.split(" ");

				if (cmdDiv.length < 3) {
					System.out.println("명령어를 확인해주세요");
					continue;
				}

				int id = Integer.parseInt(cmdDiv[2]);

				Article foundArticle = null;

				for (int i = 0; i < articles.size(); i++) {
					Article article = articles.get(i);
					if (article.id == id) {
						foundArticle = article;
						break;
					}
				}

				if (foundArticle == null) {
					System.out.printf("%d번 게시물은 존재하지 않습니다\n", id);
					continue;
				}
				System.out.println("번호 : " + foundArticle.id);
				System.out.println("날짜 : " + foundArticle.regDate);
				System.out.println("제목 : " + foundArticle.title);
				System.out.println("내용 : " + foundArticle.body);

			} else {
				System.out.println("존재하지 않는 명령어입니다");
			}
		}

		System.out.println("==프로그램 끝==");

		sc.close();
	}
}

class Article {
	int id;
	String regDate;
	String title;
	String body;

	Article(int id, String regDate, String title, String body) {
		this.id = id;
		this.regDate = regDate;
		this.title = title;
		this.body = body;
	}
}

 

메인 게시판

 

 

package com.KoreaIT.java.AM;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Util {
	/** 포맷팅 현재 날짜/시간 반환 Str */
	public static String getNowDateTimeStr() {
		// 현재 날짜/시간
		LocalDateTime now = LocalDateTime.now();
		// 포맷팅
		String formatedNow = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
		// 포맷팅 현재 날짜/시간 출력

		return formatedNow;
	}
}

시간용 util 패키지를 만들어준다

작업 26, 게시물 리스트에서 작성자의 이름이 나오도록

-join 활용
작업 27, 조회수 기능 추가

hit int (10) ungsigned not null after body

detail 및 list 노출

작업 28, 게시물 수정, 삭제시 권한 체크

	if (article.memberId != Container.session.loginedMemberId) {
		System.out.println("게시글에 대한 권한이 없습니다");
		return; 권한이 없으니 끝내줌
	}

Main

↓↑
App
디스패처 서블릿(입구컷 하는애들)
↓↑
각각의 컨트롤러 - 고객의 요청받고
↓↑
관련 서비스를 - 메인로직(판단)
↓↑
DAO

https://kouzie.github.io/jdbc/JDBC.-4%EC%9D%BC%EC%B0%A8/#controller-%EC%A0%95%EC%9D%98

작업 29, 게시물 리스트 페이징, 검색, 남은 내용 시도

select *
from article
order by desc
limit (어디부터) , (어디까지);

f6누르면 오류있어도 강제 실행해서 어디서 막히는지 보여줌
디버그 모드에서

컨트롤 쉬프트 r 하면 스프링 내 검색가능 편함

작업 21, 로그인 기능 구현, 비밀번호 시도 횟수 추가
작업 22, 컨테이너 도입, SQL 에러메세지가 console에 보이도록
작업 23, member profile 기능 추가
작업 24, 로그인, 로그아웃 체크
작업 25, 게시물 작성시 작성자의 회원번호 저장

숙제 - 노션 사용법 영상 찾아보기

게시물 조회 시 작성자 이름이 나오도록 구현해보기
join 활용

프론트 나가기 전에 복습 확실히 해두기

'DB' 카테고리의 다른 글

MySql -sqlyog 한글 깨짐 해결법  (0) 2023.04.11
DBMS,Spring 3월 23일 5회차  (0) 2023.03.30
DBMS,Spring 3월 22일 4회차  (0) 2023.03.30
DBMS,Spring 3월 21일 3회차  (0) 2023.03.30
DBMS,Spring 3월 17일 2회차  (0) 2023.03.30

작업 17, 회원가입시 아이디중복체크
작업 18, MemberController 도입
작업 19, ArticleController 도입
작업 20, MVC 구조 도입

회원가입에 필요한 필수 요소들
넣기 이름등

아이디 중복 체크하기
Boolean 에서 0은 false, 1은 true 이다.

SELECT COUNT() > 0 은 COUNT()이 0보다 크면 1 이고 , COUNT(*) 가 0보다 크지 않으면 0 이다.

DBUtil.selectRowBooleanValue(conn, sql)의 값이 1(true)이 나오면 사용중인 아이디가 있다는것.

패스워드 일치 체크하기
if (loginId.trim().length() == 0) , 아이디가 공백이면 다시 입력받도록 구현 비밀번호,

비밀번호 확인도 마찬가지로 공백이면 continue 하여 각각 비밀번호와, 비밀번호 확인만 다시 입력받도록 구현

공백만 아니라면 일단 패스워드,패스워드 확인을 받고 boolean loginPwCheck 의 값이 비밀번호와 비밀번호확인이 일치하지 않을때 false를 대입한다. loginPwCheck가 true 일때만 while문 종료하게 구현, loginPwCheck가 false이면 다시 비밀번호부터 다시 입력받도록 구현

로그인 아이디 체크

아이디 확인 -컨트롤러 도입
->app의 기능 분할

글쓰기 조건- 로그인
글삭제, 수정 권한 - 로그인 id=글쓴이 id

-서비스 도입 -컨테이너 도입

하려는 게시판 구조 MVC
Main
↓↑
App
디스패처 서블릿(입구컷 하는애들)
↓↑
각각의 컨트롤러 - 고객의 요청받고
↓↑
관련 서비스를 - 메인로직(판단)
↓↑
DAO

(Container) -> 모듈들이 들어있는 따로 파생되어있는 장소
공유되는 자원들을 모아둔 장소라고 생각하면 된다.(작업28,참고)

은행 업무에 비유

저 사이사이 왔다 갔다 하는애들은 dto

글쓴이의 이름이 나오도록 하고프면

Article 의 멤버 아이디랑

Memer의 Id(name)이랑 같아야함

module 화 라고 한다(작업 28때 했던것.) ->2023_03_24 시험때 구현못함 -> join 개념이다(작업29에 설명)

중간다리 역할 하는 녀석을 만들껀데

그것이 Container서로 공유하는 공유자원

생성자 super();
부모 생성자를 자식 생성자에서 실행하겠다
반드시 첫줄에서 써야함

https://ehddbsdl22.tistory.com/113 sql문제 연습 답

SHA-256 암호 알고리즘 그냥 알아두기
sha256 해시 생성기
qr 코드로도 만들어줌

선형 구조 vs 트리 구조
탐색 방법이 다르다

'DB' 카테고리의 다른 글

MySql -sqlyog 한글 깨짐 해결법  (0) 2023.04.11
DBMS,Spring 3월 24일 6회차  (0) 2023.03.30
DBMS,Spring 3월 22일 4회차  (0) 2023.03.30
DBMS,Spring 3월 21일 3회차  (0) 2023.03.30
DBMS,Spring 3월 17일 2회차  (0) 2023.03.30

+ Recent posts