create table board( no number, -- 글 번호 title varchar2(150) not null, -- 글 제목 writer varchar2(30) not null, -- 글 작성자 content varchar2(4000) not null, -- 글 내용 writedate varchar2(14) not null, -- 글 작성(수정)일시 yyyyMMDDHHmmss viewcount number not null, -- 조회수(최초입력 : 0), 조회시마다 1씩 증가 --답변과 관련된 속성-- refamily number not null, -- 원본글 기준으로 그 답변 글을 묶는 그룹번호, 기준글(최초 원본번호)
-- 새로운 값(글번호) -- 답변글(답변하는 글의 refamily값) restep number not null, -- 같은 refamily 묶인 글들사이에서의 정렬 순서, 기준글-0, 답변글-답변하는 글의 restep값+1 relevel number not null, -- 답변레벨, 기준글-0, 답변글-답변하는 글의 relevel+1 constraint board_pk primary key(no) )
--시퀀스: 게시판 글번호를 위한 자동증가 시퀀스 --이름 : sequence board_no_seq create sequence board_no_seq drop sequence board_no_seq
public class Utilities { //글목록에서 한페이지에 보여질 게시물의 갯수 public static final int CONTENT_PER_PAGE = 5; //한 페이지 그룹으로 묶을 페이지의 갯수 public static final int PAGE_PER_PAGEGROUP = 5; private Utilities() {}
/** * 호출된 시점의 일시를 14자리 String 값으로 만들어 return * 예) 20120512100524 (yyyyMMddHHmmss) * @return */ public static String getNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); GregorianCalendar gc = new GregorianCalendar(); Date d = gc.getTime(); String str = sdf.format(d); return str; } /** * 인수로 14자리 형태 일시를 받아 날짜만 yyyy.MM.dd 형태의 String으로 만들어 return * 목록에서 작성일시를 보여줄 때 사용할 메소드 * 예)20120512100524 - > 2012.05.12 * @param dateTime * @return */ public static String changeDayFormat(String dateTime) { return dateTime.substring(0,4) + "." + dateTime.substring(4,6) + "." + dateTime.substring(6,8); } /** * 인수로 14자리 형태의 일시를 받아 yyyyMMdd HH:mm:ss 형태의 String으로 만들어 return * - 글 상세보기에서 사용할 메소드 */ public static String changeDayTimeFormat(String dateTime) { return dateTime.substring(0,4) + "" + dateTime.substring(4,6) + "" + dateTime.substring(6,8) + " " + dateTime.substring(8, 10) + ":"+dateTime.substring(10,12) +":"+dateTime.substring(12, 14); } /** * TextArea에서 입력 받은 글 내용을 HTML로 출력 될 때에 맞는 형식으로 변경하는 메소드 * 새글등록, 답변글 등록, 글 수정시 사용 * > -> > * < -> < * \n -> <br> * 공백 - */ public static String changeContentForDB(String content) { String newContent = content.replaceAll(">", ">"); newContent = content.replaceAll("<", "<"); newContent = content.replaceAll("\n", "<br>"); newContent = content.replaceAll(" ", " "); return newContent; } /** * DB에 저장된 content를 TextArea에 출력할 형식으로 변경 * 글 수정 폼, 답글 폼 출력시 사용 * <br> -> \n * > -> > * < -> < * -> 공백 */ public static String changeContentForTextArea(String content) { String newContent = content.replaceAll(">", ">"); newContent = content.replaceAll("<", "<"); newContent = content.replaceAll("<br>", "\n"); newContent = content.replaceAll(" ", " "); return newContent; } }