1. Board 로우데이터 생성
package service;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import domain.Board;
public class BoardService {
List<Board> boards = new ArrayList<>();
{
Board board = new Board(1L, "글 제목1", "글 내용1", "작성자1");
boards.add(board);
board = new Board(2L, "글 제목2", "글 내용2", "작성자2");
boards.add(board);
boards.add(new Board((long)3, "글 제목3", "글 내용3", "작성자3"));
boards.add(new Board((long)4, "글 제목4", "글 내용4", "작성자4"));
boards.add(new Board((long)5, "글 제목5", "글 내용5", "작성자5"));
}
// 내용 생략
}
2. list() : 게시글 조회 기능
public void list() {
System.out.println("목록 조회");
for(Board board : boards) {
System.out.print(board.bno + " ");
System.out.print(board.title + " ");
System.out.print(board.content + " ");
System.out.print(board.hitCount + " ");
System.out.print(board.regDate + " ");
System.out.println(board.writer + " ");
}
}
3. register() : 게시글 등록 기능
public void register() {
System.out.println("게시글 등록");
Scanner scanner = new Scanner(System.in);
System.out.println("글번호 > ");
Long bno = Long.parseLong(scanner.nextLine());
System.out.println("제목 > ");
String title = scanner.nextLine();
System.out.println("내용 > ");
String content = scanner.nextLine();
System.out.println("작성자 > ");
String writer = scanner.nextLine();
Board board = new Board(bno, title, content, writer);
boards.add(board);
}