1. Board, Member, Reply 변수 생성
- domain : Board
package domain;
public class Board {
Long bno; // PK : 기본키
String title; // 글 제목
String content; // 글 내용
int hitCount; // 조회수
long regDate; // 작성시각
String writer; // FK : 외래키
public Board() {
// TODO Auto-generated constructor stub
}
public Board(Long bno, String title, String content, int hitCount, long regDate, String writer) {
super();
this.bno = bno;
this.title = title;
this.content = content;
this.hitCount = hitCount;
this.regDate = regDate;
this.writer = writer;
}
}
- domain : Member
package domain;
public class Member {
String id; // PK : 기본키
String pw;
String name;
public Member() {
// TODO Auto-generated constructor stub
}
public Member(String id, String pw, String name) {
super();
this.id = id;
this.pw = pw;
this.name = name;
}
}
- domain : Reply
package domain;
public class Reply {
Long rno; // PK : 기본키
String content;
long regDate;
Long bno; // FK : 외래키
String writer; // FK : 외래키
public Reply() {
// TODO Auto-generated constructor stub
}
public Reply(Long rno, String content, long regDate, Long bno, String writer) {
super();
this.rno = rno;
this.content = content;
this.regDate = regDate;
this.bno = bno;
this.writer = writer;
}
}
2. Board, Member, Reply 메서드 생성
- service : BoardService
package service;
import java.util.ArrayList;
import java.util.List;
import domain.Board;
public class BoardService {
List<Board> boards = new ArrayList<>();
{
// boards.add(new Board());
}
// 게시글 등록
public void register() {
System.out.println("글 작성");
}
public void modify() {
System.out.println("글 수정");
}
public void remove() {
System.out.println("글 삭제");
}
public void list() {
System.out.println("목록 조회");
}
public void detail() {
System.out.println("상세 조회");
}
}
- service : MemberService
package service;
import java.util.ArrayList;
import java.util.List;
import domain.Member;
public class MemberService {
List<Member> members = new ArrayList<Member>();
{
// members.add(new Member());
}
public void register() {
System.out.println("회원 가입");
}
public void modify() {
System.out.println("회원 정보 수정");
}
public void remove() {
System.out.println("회원 탈퇴");
}
public void login() {
System.out.println("로그인");
}
public void logout() {
System.out.println("로그아웃");
}
}
- service : ReplyService
package service;
import java.util.ArrayList;
import java.util.List;
import domain.Reply;
public class ReplyService {
List<Reply> replies = new ArrayList<>();
{
// replys.add(new Reply());
}
public void register() {
System.out.println("댓글 작성");
}
public void remove() {
System.out.println("댓글 삭제");
}
public void list() {
System.out.println("댓글 목록 조회");
}
}
3. Class BoardApp 생성(테스트 영역)
package app;
import java.util.Scanner;
import service.BoardService;
public class BoardApp {
public static void main(String[] args) {
BoardService boardService = new BoardService();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("1.목록조회 2.등록 3.수정 4.삭제");
int input = Integer.parseInt(scanner.nextLine());
switch (input) {
case 1:
boardService.list();
break;
case 2:
boardService.register();
break;
case 3:
boardService.modify();
break;
case 4:
boardService.remove();
break;
default:
break;
}
}
}
}