팀프로젝트에 앞서서 개별프로젝트 먼저 진행
뭐 만들지?
고민
*********************************************************
게시판 밑에 페이지 블록 묶음과 이전, 다음 링크 만들기
BoardDAO.java
package myDB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class BoardDAO {
private String user = "user01";
private String password = "user01";
private String url = "jdbc:oracle:thin:@192.168.116.128:1521:xe";
private String driver = "oracle.jdbc.driver.OracleDriver";
private Connection con;
private PreparedStatement st;
private ResultSet rs;
public BoardDAO(){
try {
Class.forName(driver);
con = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public List<BoardDTO> getlist(int curpage){
int start = 0;
int last = 0;
start = curpage*10-9;
last = curpage*10;
String sql="select * from (select rownum R, A.* from"
+"(select * from noticboard order by no desc) A)"
+"where R between ? and ?";
List<BoardDTO> ar = new ArrayList<>();
try {
st = con.prepareStatement(sql);
st.setInt(1, start);
st.setInt(2, last);
rs = st.executeQuery();
while(rs.next()){
BoardDTO b = new BoardDTO();
b.setNo(rs.getInt("no"));
b.setTitle(rs.getString("title"));
b.setWriter(rs.getString("writer"));
b.setContents(rs.getString("contents"));
ar.add(b);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ar;
}
//총 게시글 수 리턴메소드 ==> 첫페이지, 마지막페이지 리턴으로 변경
public int getCount(int curpage){
int firstPage = 0; //처음 들어갈 번호
int lastPage = 0; //마지막 들어갈 번호
int block = 1 ; //블럭 그룹번호
int pagePerBlock = 5 ; //한 블럭에 들어갈 페이지 번호 수
int count = 0;
//받아온 curpage를 가지고 어느 block에 속하는지를 구하는 조건문
if(curpage%pagePerBlock==0){
block = curpage/pagePerBlock ;
}else{
block = curpage/pagePerBlock + 1 ;
}
//block을 이용해서 firstpage, lastpage를 구하는 공식
//firstPage = (block-1)*pagePerBlock+1;
//lastPage = block*pagePerBlock ;
/*
String sql = "select count(no) from noticboard";
try {
st = con.prepareStatement(sql);
rs = st.executeQuery();
if(rs.next()){
count = rs.getInt(1);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int t = count%10;
count = count/10;
if(t!=0){
count = count +1;
}
return count;
*/
return block;
}
public int getC(){
int totalContent = 0; //전체 글 수
int totalPage = 0; //전체 페이지 수
int totalBlock = 0;
//전체 글 수를 받아 오는 query문
String sql = "select count(no) from noticboard";
try {
st = con.prepareStatement(sql);
rs = st.executeQuery();
if(rs.next()){
totalContent = rs.getInt(1);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 전체 글 수를 이용해서 전체 페이지 수를 구하는 공식
if(totalContent%10==0){
totalPage = totalContent/10 ;
}else{
totalPage = (totalContent/10) +1;
}
// totalPage를 이용해서 전체 block 수를 구하는 공식
if(totalPage%5==0){
totalBlock = totalPage/5;
}else{
totalBlock = (totalPage/5)+1;
}
return totalBlock;
}
}
listView.jsp
<%@page import="myDB.BoardDTO"%>
<%@page import="java.util.List"%>
<%@page import="myDB.BoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int curpage = Integer.parseInt(request.getParameter("curpage"));
BoardDAO d = new BoardDAO();
List<BoardDTO> ar = d.getlist(curpage);
int block = d.getCount(curpage);
int totalBlock = d.getC();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>공지사항페이지</title>
<link type="text/css" href="./practice.css" rel="stylesheet">
<style type="text/css">
table{
border: 1px solid blue;
border-collapse: collapse;
border-spacing: 0px;
width: 500px;
margin : 0 auto;
}
div{
width: 500px;
margin : 0 auto;
}
h3{
width : 500px;
margin : 0 auto;
}
</style>
</head>
<body>
<h3>
<a href="index.jsp">메인으로</a><br>
공지사항입니다</h3><br>
<table>
<tr>
<td>번호</td><td>제목</td><td>작성자</td>
</tr>
<%
for(int i=0;i<ar.size();i++){
%>
<tr>
<td><%=ar.get(i).getNo() %></td>
<td><%=ar.get(i).getTitle() %></td>
<td><%=ar.get(i).getWriter() %></td>
</tr>
<%} %>
</table>
<p></p>
<div>
<%
int start = (block-1)*5+1;
int last = block*5;
if(block > 1){%>
<a href="listView.jsp?curpage=<%=start-1%>">[이전]</a>
<%}
for(int i=start ; i<= last ; i++){
%>
<a href="listView.jsp?curpage=<%=i %>"><%=i %></a>
<%}
if(block < totalBlock){
%>
<a href="listView.jsp?curpage=<%=last+1 %>">[다음]</a>
<% }%>
</div>
</body>
</html>
*********************************************************
어제 작업한 부분에서
로그인한 회원정보 보는 페이지
1. 처음에는 DAO에 정보보는 메소드를 만들어서 불러왔으나 최근에 가입한 회원정보를 불러옴 (쿼리문 수정해야할 것으로 보임)
2. 해결책 , 차라리 세션으로 객체를 생성해서 한번에 불러오니 해결
*********************************************************
private String user = "DB아이디";
private String password = "DB암호";
private String url="jdbc:oracle:thin:@서버아이피:서버SID";
private String driver="oracle.jdbc.driver.OracleDriver";
private Connection con;
private PreparedStatement st;
private ResultSet rs; // select 문은 리턴타입이 리절트셋
*********************************************************
게시판 연습
index2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="viewList.jsp?curpage=1">공지사항보기</a>
</body>
</html>
viewList.jsp
<%@page import="notice_board.NoticeDTO"%>
<%@page import="java.util.List"%>
<%@page import="notice_board.NoticeDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int curPage = Integer.parseInt(request.getParameter("curpage") );
NoticeDAO nd = new NoticeDAO();
List<NoticeDTO> ar = nd.getList(curPage);
int block = nd.getBlock(curPage);
int start = block*5 -4;
int last = block*5;
int [] numAr = nd.getTotalBlock();
//int count = nd.getCount();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
table {
width: 800px;
border: 1px solid blue;
border-spacing: 0px;
border-collapse: collapse;
margin: 0 auto;
}
td {
border: 1px dashed blue;
text-align: center;
}
div {
width: 800px;
margin: 0 auto;
}
</style>
</head>
<body>
<table>
<tr>
<td>글번호</td><td>글제목</td><td>작성자</td>
</tr>
<%
for(int i=0;i<ar.size();i++){
%>
<tr>
<td><%=ar.get(i).getNo() %></td>
<td><%=ar.get(i).getTitle() %></td>
<td><%=ar.get(i).getWriter() %></td>
</tr>
<%} %>
</table>
<div>
<% if(block>1){ %>
<a href="viewList.jsp?curpage=<%= start-1%>">[이전]</a>
<%} %>
<%
if(block>=numAr[1]){
last = numAr[0];
}
for(int i=start; i<=last;i++){ %>
<a href="viewList.jsp?curpage=<%=i %>"><%=i%></a>
<%}
if(block < numAr[1]){%>
<a href="viewList.jsp?curpage=<%=last+1 %>">[다음]</a>
<%}%>
</div>
</body>
</html>
NoticeDTO.java
package notice_board;
public class NoticeDTO {
private int no;
private String writer;
private String title;
private String content;
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContents() {
return content;
}
public void setContents(String content) {
this.content = content;
}
}
NoticeDAO.java
package notice_board;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class NoticeDAO {
private String user = "user01";
private String password = "user01";
private String url="jdbc:oracle:thin:@192.168.116.128:1521:xe";
private String driver="oracle.jdbc.driver.OracleDriver";
private Connection con;
private PreparedStatement st;
private ResultSet rs;
public NoticeDAO(){
try {
Class.forName(driver);
con = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//******************************************************//
//DB에서 리스트를 꺼내오는 메소드
public List<NoticeDTO> getList(int curPage){
List<NoticeDTO> ar = new ArrayList<>();
//curPage =1 , 2
int start = 0 ; // setInt 1번에 들어갈 번호 , 1 , 11 ...
int last = 0; // setInt 2번에 들어갈 번호 , 10 , 20 ...
//start = curPage*10-9;
start = (curPage*10)-9;
last = curPage * 10;
String sql ="select * from"
+"(select rownum R, A.* from"
+"(select * from noticboard order by no desc) A)"
+"where R between ? and ?";
try {
st = con.prepareStatement(sql);
st.setInt(1, start);
st.setInt(2, last);
rs = st.executeQuery();
while(rs.next()){
NoticeDTO n = new NoticeDTO();
n.setNo(rs.getInt("no"));
n.setTitle(rs.getString("title"));
n.setWriter(rs.getString("writer"));
n.setContents(rs.getString("contents"));
ar.add(n);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ar;
}
public int[] getTotalBlock(){
int [] numAr = new int [2];
int pages=0;// 총페이지 수를 담을 변수
String sql = "select count(no) from noticboard";
try {
st = con.prepareStatement(sql);
rs = st.executeQuery();
if(rs.next()){
pages = rs.getInt(1);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(pages%10 ==0){
pages = pages/10;
}else {
pages = pages/10+1;
}
int totalBlock=0;//총 블럭수를 담을 변수
if(pages%5==0){
totalBlock= pages/5;
}else {
totalBlock= pages/5+1;
}
numAr[0]=pages;
numAr[1]=totalBlock;
return numAr;
}
//******************************************************//
//페이지당 블럭을 알아오는 메서드
//block 번호를 가지고 페이지 번호를 알아내려함
//block 이 1이라면 페이지 번호는 1~5까지 출력
//block 이 2 이라면 페이지 번호는 6~10까지 출력
public int getBlock(int curPage){
int block=0; //블럭의 번호를 저장하는 변수
int pagePerBlock=5; //블럭당 페이지 수
if(curPage%pagePerBlock==0){
block = curPage/pagePerBlock;
}else{
block = curPage/pagePerBlock+1;
}
return block;
}
}
*********************************************************
다음주까지 개인프로젝트 끝
같은 주제를
다른 사람들이 다른 방식으로 표현
주제 : 백주부가 지금까지 발표한 레시피를 소개하는 페이지
요구사항
1.회원제 : 회원가입 후 로그인
2.공지사항 : 관리자
3.방명록 : 회원만
4.Q&A게시판 : 회원만
5.게시판 리스트 보기 : 비회원도 가능, 그러나 상세보기는 회원만 가능
방명록,Q&A게시판을 사용하기 위해서는 회원가입, 로그인
[회원정보]
-이름
-아이디
-비밀번호
-전화번호
-성별
-직업
-나이
요구사항
검색기능 - 게시판(option)
관리자모드 - 회원검색기능(수정,삭제)(option)
관리자는 모든 게시판을 수정 삭제 가능(option)
회원은 각자의 정보를 수정할 수 있는 페이지가 있어야함.
테이블
회원테이블
공지사항테이블
방명록테이블
Q&A테이블
DB에 총 4개의 테이블 구성
PPT로 계획서 만들어서 제출
폴더, 패키지 나누기
*******************************************************
카페24 - DB호스팅 - MySQL