Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
Tags
- 서버
- 스프링부트
- oracle
- JavaScript
- 미니정리
- spring
- 프론트엔드
- 백엔드
- 자바
- 디자인 패턴
- 오라클
- 코드 테스트
- java
- BACK-END
- 쿼리
- SQL
- 코드테스트
- 자바스크립트
- MySQL
- node.js
- jsp
- 스프링
- 데이터베이스
- web
- 정리
- jpa
- 프로그래머스
- Next.js
- 프런트엔드
- 알고리즘
Archives
- Today
- Total
참치코더의 꿈 메모장
2021/08/04 Java - 토이 프로젝트(게시판 만들기) 본문
728x90
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
package j_collection;
import java.util.ArrayList;
import java.util.HashMap;
import org.omg.CORBA.UserException;
import e_oop.ScanUtil;
public class Board {
public static int num = 1;
public static void main(String[] args) {
/*
* ArrayList와 HashMap을 사용해 게시판 테이블을 만들고,
* 조회, 등록, 수정, 삭제가 가능한 게시판을 만들어주세요.
*
* 게시판 테이블 컬럼 : 번호(PK), 제목, 내용, 작성자, 작성일
*
*/
//게시판 테이블
Kr_date date = new Kr_date(); // 오늘 날짜 가져오기
HashMap<String, String> board = new HashMap<>();
ArrayList<HashMap<String, String>> table = new ArrayList<>();
board = new HashMap<>();
/*board.put("번호", "0");
board.put("제목", "test");
board.put("내용", "test");
board.put("작성자", "admin");
board.put("작성일", date.today_date());
table.add(board);
*/
//게시판 동작 선택
while (true) {
System.out.println("게시판 0.1");
System.out.print("1.조회\t2.등록\t3.수정\t4.삭제>");
int val = ScanUtil.nextInt();
switch (val) {
case 1:
System.out.println("번호\t제목\t내용\t작성자\t작성일");
for (int i = 0; i < table.size(); i++) {
System.out.println(table.get(i).get("번호")+
"\t"+table.get(i).get("제목")+
"\t"+table.get(i).get("내용")+
"\t"+table.get(i).get("작성자")+
"\t"+table.get(i).get("작성일"));
}
break;
case 2:
//System.out.println("등록하실 내용을 입력해 주세요.");
board = new HashMap<>();
board.put("번호", ""+num++);
System.out.print("등록하실 제목을 입력하세요>");
board.put("제목", ScanUtil.nextLine());
System.out.print("등록하실 내용을 입력하세요>");
board.put("내용", ScanUtil.nextLine());
System.out.print("등록하실 작성자를 입력하세요>");
board.put("작성자",ScanUtil.nextLine());
board.put("작성일",date.today_date());
table.add(board);
break;
case 3:
//board = new HashMap<>();
System.out.print("수정하실 내용의 번호를 입력해 주세요>");
String check_num = ScanUtil.nextLine();
for (int i = 0; i < table.size(); i++) {
if (check_num.equals(board.get("번호"))) {
System.out.print("변경하실 제목을 입력하세요>");
board.put("제목", ScanUtil.nextLine());
System.out.print("변경하실 내용을 입력하세요>");
board.put("내용", ScanUtil.nextLine());
System.out.print("변경하실 작성자를 입력하세요>");
board.put("작성자",ScanUtil.nextLine());
board.put("작성일",date.today_date());
break;
}
}
break;
case 4:
System.out.print("삭제하실 내용의 번호를 입력해 주세요>");
String del_num = ScanUtil.nextLine();
for (int i = 0; i < table.size(); i++) {
if(del_num.equals(board.get("번호"))){
board.clear();
table.remove(board);
//board.remove("번호");
//board.remove("제목");
//board.remove("내용");
//board.remove("작성자");
//board.remove("작성일");
break;
}
}
break;
}
}
}
}
|
cs |
자바만을 이용해서 게시판 만드는걸 하였다.
728x90
'JAVA' 카테고리의 다른 글
| 2020/08/11 Java - 패키지와 접근 제한자 (0) | 2021.08.11 |
|---|---|
| 2021/08/10 Java - 인스턴스 멤버와 정적 멤버 (0) | 2021.08.10 |
| 2021/08/02 Java - 메소드 (0) | 2021.08.02 |
| 2021/08/01 Java - 생성자 (0) | 2021.08.01 |
| 2021/08/01 Java - 필드 (0) | 2021.08.01 |
Comments