[Day4] JSP/JDBC 4 [10/31]
์ฃผ์) PL/SQL ์ ์ ์ฅํ๋ก์์ ์์ ์์๋ก ๋ดค์ ๋ ํ ์ด๋ธ๋ช ๊ณผ ์นผ๋ผ๋ช ์ ๋ณ์๋ก ์ฌ์ฉํ์ง ๋ชปํจ
๊ฒ์ํ ์์ฑ
1. ๊ฒ์ํ(board) ํ ์ด๋ธ ์์ฑ
C# .net (๋ท๋ท)
seq : ์ผ๋ จ๋ฒํธ, ๊ธฐ๋ณธํค. ๊ฐ ๊ธ์ ๊ตฌ๋ถํ๋ ๋ฒํธ์
๋๋ค. writer : ๊ธ์ด์ด pwd : ๋น๋ฐ๋ฒํธ email : ๋ฉ์ผ์ฃผ์ title : ์ ๋ชฉ writedate : ๊ธ์ด ์ผ์ readed : ์กฐํ์ mode : ๊ธ์ ํ์( 0-TEXT, 1-HTML ํ๊ทธ ํ์ฉ ) content : ๊ธ์ ๋ด์ฉ |
CREATE SEQUENCE seq_tbl_cstVSBoard;
CREATE TABLE tbl_cstVSBoard(
seq NUMBER NOT NULL PRIMARY KEY
, writer VARCHAR2(20) NOT NULL
, pwd VARCHAR2(20) NOT NULL
, email VARCHAR2(100)
, title VARCHAR2(200) NOT NULL
, writedate DATE DEFAULT SYSDATE
, readed NUMBER DEFAULT 0
, tag NUMBER(1) DEFAULT 0 -- 0 ํ
์คํธ๋ชจ๋ 1 HTML๋ชจ๋
, content CLOB
);
2. ๊ธ์ฐ๊ธฐ
๊ธ๋ชฉ๋ก ํ์ด์ง [๊ธ์ฐ๊ธฐ]๋ฒํผ -> ํด๋ฆญ -> ๊ธ์ฐ๊ธฐ(์๊ธ์์ฑ) ํ์ด์ง ์ ๋ชฉ/๋ด์ฉ/๋ฑ๋ฑ ์ ๋ ฅ ์์ [์ ์ฅ][๋ชฉ๋ก][์ทจ์] ๋ฑ๋ฑ ใด์ ์ฅ ํด๋ฆญ |
3. domain.BoardDTO ์ ์ธ
4. [์์]
Controller -> Handler -> Service -> DAO -> DB (Oracle)
์ฒ๋ฆฌ ์๋ฃ๋๋ฉด ๋ฐ๋๋ก ๊ฒฐ๊ณผ๋ฌผ ๋ฐํ
Controller - Service - Handler(Model) -> DAO -> ์ค๋ผํด,
insert(dto)
dto dto dto
* ์ฌ๊ธฐ์ (Controller + Model + View) ํ๋๋ก ์ฒ๋ฆฌ
[๊ธฐ๋ณธ์ค์ ]
* main
Connection conn = DBConn.getcConnection();
BoardDAO dao = new BoardDAOImpl(conn);
BoardService service = new BoradService(dao);
BoardController controller = new BoardController(service);
controller.boardStart();
* DTO
package days03.board;
import java.sql.Date;
public class BoardDTO {
private int seq;
private String writer;
private String pwd;
private String email;
private String title;
private Date writedate;
private int readed;
private int tag;
private String content;
public BoardDTO() {
super();
}
public BoardDTO(int seq, String writer, String pwd, String email, String title, Date writedate, int readed, int tag,
String content) {
super();
this.seq = seq;
this.writer = writer;
this.pwd = pwd;
this.email = email;
this.title = title;
this.writedate = writedate;
this.readed = readed;
this.tag = tag;
this.content = content;
}
public int getSeq() {
return seq;
}
public void setSeq(int seq) {
this.seq = seq;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getWritedate() {
return writedate;
}
public void setWritedate(Date writedate) {
this.writedate = writedate;
}
public int getReaded() {
return readed;
}
public void setReaded(int readed) {
this.readed = readed;
}
public int getTag() {
return tag;
}
public void setTag(int tag) {
this.tag = tag;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Override
public String toString() {
return "BoardDTO [seq=" + seq + ", writer=" + writer + ", pwd=" + pwd + ", email=" + email + ", title=" + title
+ ", writedate=" + writedate + ", readed=" + readed + ", tag=" + tag + ", content=" + content + "]";
}
} // class
* DAO interface
package days03.board;
import java.sql.SQLException;
import java.util.ArrayList;
public interface BoardDAO {
// 1. ๊ธ ์ฐ๊ธฐ
int insert( BoardDTO dto ) throws SQLException;
// 2. ๊ธ ๋ชฉ๋ก
ArrayList<BoardDTO> select( int currentPage, int numberPerPage ) throws SQLException;
// 3. ๊ธ ์์ธ๋ณด๊ธฐ
// 3-1. ์กฐํ์ ์ฆ๊ฐ
int increaseReaded(int seq) throws SQLException;
// 3-2. ํด๋น ๊ฒ์๊ธ ๋ฐํ
BoardDTO view(int seq) throws SQLException;
// 4. ๊ธ ์ญ์
// 4-1. ๋น๋ฐ๋ฒํธ ํ์ธ
String getOriginalPwd(int seq) throws SQLException;
// 4-2. ๊ธ ์ญ์ .
int delete(int seq) throws SQLException;
// 5. ์์
int update(BoardDTO dto) throws SQLException;
// 6. ๊ฒ์
ArrayList<BoardDTO> search( int currentPage, int numberPerPage, int searchCondition, String searchWord) throws SQLException;
// ์ด๋ ์ฝ๋์
int getTotalRecords() throws SQLException;
// ์ดํ์ด์ง์
int getTotalPages(int numberPerPage) throws SQLException;
// ๊ฒ์ํ๊ธฐ - ์ด๋ ์ฝ๋์
int getTotalRecords(int searchCondition, String searchWord) throws SQLException;
// ๊ฒ์ํ๊ธฐ - ์ดํ์ด์ง์
int getTotalPages(int numberPerPage, int searchCondition, String searchWord) throws SQLException;
} // interface
* DAOImpl
public class BoardDAOImpl implements BoardDAO{
private Connection conn = null;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
public BoardDAOImpl() {}
// 1. ์์ฑ์ DI( ์์กด์ฑ ์ฃผ์
)
public BoardDAOImpl(Connection conn) {
this.conn = conn;
}
// 2. setter DI
public void setConn(Connection conn) {
this.conn = conn;
}
}
* Service
public class BoardService {
private BoardDAO dao = null;
// 1. ์์ฑ์ DI
public BoardService(BoardDAO dao) {
super();
this.dao = dao;
}
// 2. setter DI
public void setDao(BoardDAO dao) {
this.dao = dao;
}
}
* Controller
public class BoardController {
// ์์ฒญ(C) + ๋ก์ง์ฒ๋ฆฌ(M) + ์ถ๋ ฅ(V)
private BoardService service = null;
private int selectedNumber = 1;
private Scanner scanner = null;
public BoardController() {
super();
this.scanner = new Scanner(System.in);
}
// 1. ์์ฑ์ DI(์์กด์ฑ ์ฃผ์
)
public BoardController(BoardService service) {
this();
this.service = service;
}
}
public void boardStart() {
while(true) {
๊ฒ์ํ๋ฉ๋ด์ถ๋ ฅ(); //
๊ฒ์ํ๋ฉ๋ด์ ํ(); // ์์ฒญ(C) +
๊ฒ์ํ๋ฉ๋ด์ฒ๋ฆฌ(); // Model + View X
} // while
}
private void ๊ฒ์ํ๋ฉ๋ด์ถ๋ ฅ() {
String [] menus = {"์๊ธ", "๋ชฉ๋ก", "๋ณด๊ธฐ", "์์ ", "์ญ์ ", "๊ฒ์", "์ข
๋ฃ" };
System.out.print("[ ๋ฉ๋ด ] ");
for (int i = 0; i < menus.length; i++) {
System.out.printf("%d. %s\t", i+1, menus[i]);
} // for
System.out.println();
}
private void ๊ฒ์ํ๋ฉ๋ด์ ํ() {
System.out.print("> ๋ฉ๋ด ์ ํํ์ธ์ ? ");
selectedNumber = scanner.nextInt(); // 1 ์ํฐ 13,10
scanner.nextLine(); // 13,10 ๋ฒ๋ฆผ.
}
private void ๊ฒ์ํ๋ฉ๋ด์ฒ๋ฆฌ() {
switch ( selectedNumber ) {
case 1: // "์๊ธ"
์๊ธ์ฐ๊ธฐ();
break;
case 2: // , "๋ชฉ๋ก"
๋ชฉ๋ก๋ณด๊ธฐ();
break;
case 3: // , "๋ณด๊ธฐ",
์์ธ๋ณด๊ธฐ();
break;
case 4: // "์์ "
์์ ํ๊ธฐ();
break;
case 5: // , "์ญ์
์ญ์ ํ๊ธฐ();
break;
case 6: // ", "๊ฒ์"
break;
case 7: // , "์ข
๋ฃ"
exit();
break;
default:
System.out.println("\t\t[๊ฒฝ๊ณ ] ๋ฉ๋ด ์ ํ ์๋ชปํ๋ค( 1~6)!!!");
break;
} // switch
}
private static void exit() {
System.out.println("\t\t ํ๋ก๊ทธ๋จ ์ข
๋ฃ !!!");
DBConn.close();
System.exit(-1);
}
[1. ๊ธ์ฐ๊ธฐ]
๊ธ์ฐ๊ธฐ ์์ฒญ
-> 1) DB insert
-> 2) ๋ก๊ทธ ๊ธฐ๋ก
-> 3) ์์ฑ์์๊ฒ ํฌ์ธํธ 1์ฆ๊ฐ update
1), 2), 3) ๋ชจ๋ ์ฑ๊ณตํด์ผ ์ฑ๊ณตํ๋ ์ฒ๋ฆฌ = ํธ๋์ญ์ ์ฒ๋ฆฌ (transaction)
1) DAOImpl
@Override
public int insert(BoardDTO dto) throws SQLException {
String sql = "INSERT INTO TBL_CSTVSBOARD "
+ " ( seq, writer, pwd, email, title, tag, content )"
+ " VALUES ( SEQ_TBL_CSTVSBOARD.NEXTVAL , ? , ? , ? , ? , ? , ? ) ";
this.pstmt = this.conn.prepareStatement(sql);
// ? , ? , ? , ? , ? , ?
this.pstmt.setString(1, dto.getWriter());
this.pstmt.setString(2, dto.getPwd());
this.pstmt.setString(3, dto.getEmail());
this.pstmt.setString(4, dto.getTitle());
this.pstmt.setInt(5, dto.getTag());
this.pstmt.setString(6, dto.getContent());
int rowCount = this.pstmt.executeUpdate();
this.pstmt.close();
return rowCount;
}
2) DAOImpl test
@Test
void insert_test() {
//fail("Not yet implemented");
Connection conn = DBConn.getConnection();
BoardDAOImpl dao = new BoardDAOImpl(conn);
BoardDTO dto = new BoardDTO();
// writer, pwd, email, title, tag, content
dto.setWriter("ํ๊ธธ๋");
dto.setPwd("1234");
dto.setEmail("hong@naver.com");
dto.setTitle("์ฒซ ๋ฒ์งธ ๊ฒ์๊ธ - ๋จ์ ํ
์คํธ ");
dto.setTag(0); // ํ
์คํธ ๋ชจ๋
dto.setContent("์ฒซ ๋ฒ์งธ ๊ฒ์๊ธ ๋ด์ฉ");
try {
int rowCount = dao.insert(dto);
if( rowCount == 1 ) {
System.out.println(" ๊ธ์ฐ๊ธฐ ๋จ์ ํ
์คํธ ์ฑ๊ณต!!!");
}else {
System.out.println(" ๊ธ์ฐ๊ธฐ ์คํจ!!!");
}
} catch (SQLException e) {
e.printStackTrace();
}
DBConn.close();
}
3) Service
public int insertService( BoardDTO dto) {
int rowCount = 0;
try {
// ํธ๋์ญ์ ์ฒ๋ฆฌ ์์ T1
// 1. ๋ก๊ทธ ๊ธฐ๋ก ์๋น์ค
System.out.println("> ๊ฒ์๊ธ ์ฐ๊ธฐ(์ถ๊ฐ) -> ๋ก๊ทธ ๊ธฐ๋ก ์์
...");
// 2. ๊ฒ์๊ธ ์ถ๊ฐ
rowCount = this.dao.insert(dto);
// 3. ์์ฑ์์ ํฌ์ธํธ 1์ฆ๊ฐ - update
// ํ์ํ
์ด๋ธ X - point ์ปฌ๋ผ X
// this.dao.updateMemberPoint(dto.getWriter());
System.out.println("> ๊ฒ์๊ธ ์ฐ๊ธฐ(์ถ๊ฐ) ์์ฑ์ ํฌ์ธํธ ์ฆ๊ฐ this. dao.update~() ..");
// ์ปค๋ฐ T2
} catch (SQLException e) {
// ๋กค๋ฐฑ T3
e.printStackTrace();
}
return rowCount;
}
4) Service ํ ์คํธ
@Test
void inserService_test() {
Connection conn = DBConn.getConnection();
BoardDAOImpl dao = new BoardDAOImpl(conn);
BoardService service = new BoardService(dao);
BoardDTO dto = new BoardDTO();
// writer, pwd, email, title, tag, content
dto.setWriter("ํ๊ธธ๋");
dto.setPwd("1234");
dto.setEmail("hong@naver.com");
dto.setTitle("๋ ๋ฒ์งธ ๊ฒ์๊ธ - ์๋น์ค ๋จ์ ํ
์คํธ ");
dto.setTag(0); // ํ
์คํธ ๋ชจ๋
dto.setContent("๋ ๋ฒ์งธ ๊ฒ์๊ธ ๋ด์ฉ");
int rowCount = service.insertService(dto);
if( rowCount == 1 ) {
System.out.println(" ๊ธ์ฐ๊ธฐ ๋จ์ ํ
์คํธ ์ฑ๊ณต!!!");
}else {
System.out.println(" ๊ธ์ฐ๊ธฐ ์คํจ!!!");
}
DBConn.close();
}
5) Controller
private void ์๊ธ์ฐ๊ธฐ() {
// ์ ๊ฒ์๊ธ ์ ๋ณด๋ฅผ ์ฝ์์์ ์
๋ ฅ
System.out.print("> writer, pwd, email, title, tag, content ์
๋ ฅ ? ");
// "๊ถ์ฌํ,1234,kkk@naver.com,์ธ ๋ฒ์งธ ๊ฒ์๊ธ,0,์ธ ๋ฒ์งธ ๊ฒ์๊ธ ๋ด์ฉ"
String [] datas = scanner.nextLine().split(",");
String writer = datas[0];
String pwd = datas[1];
String email = datas[2];
String title = datas[3];
int tag = Integer.parseInt(datas[4]);
String content = datas[5];
// [C]dto -> [S]dto-> [D]dto-> DB INSERT
BoardDTO dto = new BoardDTO();
dto.setWriter(writer);
dto.setPwd(pwd);
dto.setEmail(email);
dto.setTitle(title);
dto.setTag(tag);
dto.setContent(content);
int rowCount = this.service.insertService(dto);
if( rowCount == 1) {
System.out.println("> ์ ๊ฒ์๊ธ ์ฐ๊ธฐ ์๋ฃ!!!");
// ๊ฒ์๊ธ ๋ชฉ๋ก ํ์ด์ง ์ด๋
}
์ผ์์ ์ง();
}
private tatic void ์ผ์์ ์ง() {
System.out.println("\t\t ์ํฐ์น๋ฉด ๊ณ์ํฉ๋๋ค.");
try {
System.in.read();
System.in.skip( System.in.available() ); // 13, 10
} catch (IOException e) {
e.printStackTrace();
} // try
}
[2. ๋ชฉ๋ก๋ณด๊ธฐ]
1) DAO Impl
@Override
public ArrayList<BoardDTO> select(int currentPage, int numberPerPage) throws SQLException {
ArrayList<BoardDTO> list = null;
BoardDTO dto = null;
int begin = (currentPage-1)*numberPerPage + 1;
int end = begin + numberPerPage -1;
String sql =
" SELECT b.* "
+ " FROM ( "
+ " SELECT ROWNUM no, t.* "
+ " FROM ( "
+ " SELECT seq, writer, email, title, readed, writedate "
+ " FROM tbl_cstvsboard "
+ " ORDER BY seq DESC "
+ " ) t "
+ " ) b "
+ " WHERE b.no BETWEEN ? AND ?";
this.pstmt = this.conn.prepareStatement(sql);
// BETWEEN ? AND ?"
this.pstmt.setInt(1, begin);
this.pstmt.setInt(2, end);
this.rs = this.pstmt.executeQuery();
// int no, seq, readed;
// String writer, email, title;
// Date writedate;
if ( this.rs.next()) {
list = new ArrayList<BoardDTO>();
do {
dto = new BoardDTO();
dto.setSeq(this.rs.getInt("seq"));
dto.setReaded(this.rs.getInt("readed"));
dto.setWriter( this.rs.getString("writer"));
dto.setEmail( this.rs.getString("email"));
dto.setTitle( this.rs.getString("title"));
dto.setWritedate(this.rs.getDate("writedate"));
list.add(dto);
} while ( this.rs.next() );
} // if
this.rs.close(); //
this.pstmt.close();
return list; // ๊ฒ์๊ธ์ด ์กด์ฌํ์ง ์์ผ๋ฉด list = null ..
}
2) DAO Impl ํ ์คํธ
@Test
void select_test() {
//fail("Not yet implemented");
Connection conn = DBConn.getConnection();
BoardDAOImpl dao = new BoardDAOImpl(conn);
ArrayList<BoardDTO> list = null;
try {
list = dao.select(1, 15); // 1๋ฒํ์ด์ง, 15๊ฐ ์ถ๋ ฅ
// ์ถ๋ ฅ
Iterator<BoardDTO> ir = list.iterator();
while (ir.hasNext()) {
BoardDTO dto = ir.next();
System.out.println( dto );
}
} catch (SQLException e) {
e.printStackTrace();
}
DBConn.close();
}
3) Service
// 2. ๊ฒ์๊ธ ๋ชฉ๋ก ์๋น์ค ๋ฉ์๋
public ArrayList<BoardDTO> selectService( int currentPage, int numberPerPage ){
ArrayList<BoardDTO> list = null;
try {
// 1. ๋ก๊ทธ ๊ธฐ๋ก ์๋น์ค
System.out.println("> ๊ฒ์๊ธ ๋ชฉ๋ก -> ๋ก๊ทธ ๊ธฐ๋ก ์์
...");
// 2.
list = this.dao.select(currentPage, numberPerPage);
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
4) Service ํ ์คํธ
5) Controller
private void ๋ชฉ๋ก๋ณด๊ธฐ() {
// 357 INSERT
// BoardService.selectService()/ BoardDAO.select()
System.out.print("> ํ์ฌ ํ์ด์ง( currentPage) ์
๋ ฅ ? " );
this.currentPage = this.scanner.nextInt();
this.scanner.nextLine(); // 13,10
ArrayList<BoardDTO> list = this.service.selectService(this.currentPage, this.numberPerPage);
// M[V]C - ์ถ๋ ฅ ๋ด๋น ๋ทฐ.
System.out.println("\t\t\t ๊ฒ์ํ");
System.out.println("--------------------------------------------------------------");
System.out.printf("%s\t%-40s\t%s\t%-10s\t%s\n",
"๊ธ๋ฒํธ","๊ธ์ ๋ชฉ","๊ธ์ด์ด","์์ฑ์ผ","์กฐํ์");
System.out.println("--------------------------------------------------------------");
if ( list == null) {
System.out.println("\t\t ๊ฒ์๊ธ ์กด์ฌ X ");
} else {
Iterator<BoardDTO> ir =list.iterator();
while (ir.hasNext()) {
BoardDTO dto = ir.next();
System.out.printf("%d\t%-30s %s\t%-10s\t%d\n",
dto.getSeq()
, dto.getTitle()
, dto.getWriter()
, dto.getWritedate()
, dto.getReaded()
);
}
} // if
System.out.println("--------------------------------------------------------------");
// System.out.println("\t\t\t [1] 2 3 4 5 6 7 8 9 10 >"); // ํ์ด์ง๋ธ๋ญ
String pagingBlock = this.service.pagingService(
this.currentPage
, this.numberPerPage
, this.numberOfPageBlock
);
System.out.println(pagingBlock);
System.out.println("--------------------------------------------------------------");
์ผ์์ ์ง();
}
[3. ์์ธ๋ณด๊ธฐ]
1) DAO Impl
// 3-1. ์กฐํ์ ์ฆ๊ฐ
// ๋จ์ ํ
์คํธ
@Override
public int increaseReaded(int seq) throws SQLException {
String sql = "UPDATE tbl_cstvsboard "
+ "SET readed = readed + 1 "
+ "WHERE seq = ? ";
this.pstmt = this.conn.prepareStatement(sql);
// ?
this.pstmt.setInt(1, seq);
int rowCount = this.pstmt.executeUpdate();
this.pstmt.close();
return rowCount;
}
// 3-2. ํด๋น ๊ฒ์๊ธ ์ ๋ณด ๋ฐํ
@Override
public BoardDTO view(int seq) throws SQLException {
String sql = " SELECT seq, writer, email, title, readed, writedate, content "
+ " FROM tbl_cstvsboard "
+ " WHERE seq = ? ";
this.pstmt = this.conn.prepareStatement(sql);
// ?
this.pstmt.setInt(1, seq);
this.rs = this.pstmt.executeQuery() ;
BoardDTO dto = null;
if( rs.next() ) {
dto = new BoardDTO();
dto.setSeq( rs.getInt("seq") );
dto.setWriter(rs.getString("writer"));
dto.setEmail(rs.getString("email"));
dto.setTitle(rs.getString("title"));
dto.setReaded( rs.getInt("readed") );
dto.setWritedate( rs.getDate("writedate"));
dto.setContent(rs.getString("content"));
} // if
this.pstmt.close();
this.rs.close();
// ํด๋น ๊ฒ์๊ธ์ด ์๋ ๊ฒฝ์ฐ๋ dto = null
return dto;
}
2) DAO Impl ํ ์คํธ
@Test
void increaseReaded_test() {
//fail("Not yet implemented");
Connection conn = DBConn.getConnection();
BoardDAOImpl dao = new BoardDAOImpl(conn);
try {
int rowCount = dao.increaseReaded( 363 );
System.out.println( rowCount );
} catch (SQLException e) {
e.printStackTrace();
}
DBConn.close();
}
3) Service
// 3. ๊ฒ์๊ธ ์์ธ ๋ณด๊ธฐ ์๋น์ค ๋ฉ์๋
public BoardDTO viewService(int seq) {
BoardDTO dto = null;
try {
// 1. ๋ก๊ทธ ๊ธฐ๋ก ์๋น์ค
System.out.println("> ๊ฒ์๊ธ ์์ธ๋ณด๊ธฐ -> ๋ก๊ทธ ๊ธฐ๋ก ์์
...");
// 2. ์กฐํ์ ์ฆ๊ฐ
this.dao.increaseReaded(seq);
// 3.
dto = this.dao. view(seq);
} catch (SQLException e) {
e.printStackTrace();
}
return dto;
}
4) Service ํ ์คํธ
5) Controller
private void ์์ธ๋ณด๊ธฐ() {
System.out.print("> ๊ฒ์๊ธ ๋ฒํธ(seq) ์
๋ ฅ ? " );
int seq = this.scanner.nextInt();
this.scanner.nextLine(); // 13,10
BoardDTO dto = this.service.viewService(seq);
if( dto == null ) {
System.out.println("> ํด๋น ๊ฒ์๊ธ ์กด์ฌ X ");
return ;
}
//
System.out.println("\tใฑ. ๊ธ๋ฒํธ : " + seq );
System.out.println("\tใด. ์์ฑ์ : " + dto.getWriter() );
System.out.println("\tใท. ์กฐํ์ : " + dto.getReaded() );
System.out.println("\tใน. ๊ธ์ ๋ชฉ : " + dto.getTitle() );
System.out.println("\tใ
. ๊ธ๋ด์ฉ : " + dto.getContent() );
System.out.println("\tใ
. ์์ฑ์ผ : " + dto.getWritedate() );
System.out.println("\t\n [์์ ] [์ญ์ ] [๋ชฉ๋ก(home)]");
์ผ์์ ์ง();
}
[4. ์์ ํ๊ธฐ]
1) DAO Impl
@Override
public int update(BoardDTO dto) throws SQLException {
String sql = "UPDATE tbl_cstvsboard "
+ " SET email=?, title=?, content=? "
+ " WHERE seq = ? ";
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setString(1, dto.getEmail());
this.pstmt.setString(2, dto.getTitle());
this.pstmt.setString(3, dto.getContent());
this.pstmt.setInt(4, dto.getSeq());
int rowCount = this.pstmt.executeUpdate();
this.pstmt.close();
return rowCount;
}
2) DAO Impl ํ ์คํธ
3) Service
// seq, email, title, content
public int updateService(BoardDTO dto) {
int rowCount = 0;
try {
// 1. ๋ก๊ทธ ๊ธฐ๋ก
// 2.
// 3.
rowCount = this.dao.update( dto );
} catch (SQLException e) {
e.printStackTrace();
}
return rowCount;
}
4) Service ํ ์คํธ
5) Controller
private void ์์ ํ๊ธฐ() {
System.out.print("> ์์ ํ ๊ธ๋ฒํธ(seq), ์ด๋ฉ์ผ, ์ ๋ชฉ, ๋ด์ฉ ์
๋ ฅ ? ");
int seq = this.scanner.nextInt();
// ์์ ํ ๊ธ ๋ฒํธ์ ๊ฒ์๊ธ ์ ๋ณด ์ถ๋ ฅ..
BoardDTO dto = this.service.viewService(seq);
if( dto == null ) {
System.out.println("> ํด๋น ๊ฒ์๊ธ ์กด์ฌ X ");
return ;
}
System.out.println("\tใฑ. ๊ธ๋ฒํธ : " + seq );
System.out.println("\tใด. ์์ฑ์ : " + dto.getWriter() );
System.out.println("\tใท. ์กฐํ์ : " + dto.getReaded() );
System.out.println("\tใน. ๊ธ์ ๋ชฉ : " + dto.getTitle() );
System.out.println("\tใ
. ๊ธ๋ด์ฉ : " + dto.getContent() );
// ์์ ์ผ, ์์ฑ์ผ
System.out.println("\tใ
. ์์ฑ์ผ : " + dto.getWritedate() );
System.out.println("\t\n [์์ ] [์ญ์ ] [๋ชฉ๋ก(home)]");
// ์ด๋ฉ์ผ/์ ๋ชฉ/๋ด์ฉ ๋ง ์์ .
String email = this.scanner.next();
String title = this.scanner.next();
String content = this.scanner.next();
this.scanner.nextLine(); // 13.10
// this.service.updateService( seq, email , title, cotent);
dto = new BoardDTO();
dto.setSeq(seq);
dto.setEmail(email);
dto.setTitle(title);
dto.setContent(content);
int rowCount = this.service.updateService( dto);
if( rowCount == 1 ) {
System.out.printf("> ๊ธ๋ฒํธ( %d ) ๊ฒ์๊ธ ์์ ์๋ฃ!!!\n ", seq);
}
์ผ์์ ์ง();
}
[5. ์ญ์ ํ๊ธฐ]
1) DAO Impl
// 4. ์ญ์
@Override
public String getOriginalPwd(int seq) throws SQLException {
String pwd = null;
String sql = "SELECT pwd "
+ " FROM tbl_cstvsboard "
+ " WHERE seq = ? ";
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setInt(1, seq);
this.rs = this.pstmt.executeQuery() ;
if( rs.next() ) {
pwd = rs.getString("pwd");
}
this.pstmt.close();
this.rs.close();
return pwd;
}
@Override
public int delete(int seq) throws SQLException {
String sql = "DELETE FROM tbl_cstvsboard "
+ " WHERE seq = ? ";
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setInt(1, seq);
int rowCount = this.pstmt.executeUpdate();
this.pstmt.close();
return rowCount;
}
2) DAO Impl ํ ์คํธ
3) Service
public int deleteService(int seq, String pwd) {
int result = 0;
try {
// ์ ์ฅ ํ๋ก์์
// 1.
String originalPwd = this.dao.getOriginalPwd(seq);
//
if( originalPwd.equals( pwd ) ) {
// 2.
result = this.dao.delete( seq );
}else {
result = -1;
}
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}
4) Service ํ ์คํธ
5) Controller
private void ์ญ์ ํ๊ธฐ() {
// 1. ์ญ์ ํ ๊ธ๋ฒํธ(seq) ์
๋ ฅ
// 2. ๊ฒ์๊ธ ๋น๋ฐ๋ฒํธ ์
๋ ฅ
System.out.print("> ์ญ์ ํ ๊ธ๋ฒํธ(seq), ๋น๋ฐ๋ฒํธ(pwd) ์
๋ ฅ ? ");
int seq = this.scanner.nextInt();
String pwd = this.scanner.next();
this.scanner.nextLine(); // 13,10
// -1(๋น๋ฐ๋ฒํธ ํ๋ฆฐ ๊ฒฝ์ฐ ) 1(์ญ์ ์ฑ๊ณต ) 0(์ญ์ ์คํจ )
int result = this.service.deleteService(seq, pwd);
if(result == -1 ) {
System.out.println("> ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ฆฝ๋๋ค. ");
}else if( result == 1 ){
System.out.println("> ๊ฒ์๊ธ ์ญ์ ์๋ฃ!!!");
}else if( result == 0 ) {
System.out.println("> ๊ฒ์๊ธ ์ญ์ ์คํจ!!!");
}
์ผ์์ ์ง();
}
[6. ๊ฒ์ํ๊ธฐ]
1) DAO Impl
// ํ ํ์ด์ง : 10 ์ถ๋ ฅ numberPerPagge
// ํ์ฌ ํ์ด์ง : 1 currentPage
// ๊ฒ์๋ ๊ฒฐ๊ณผ : 35 ํ -> 1๋ฒ ํ์ด์ง 10๊ฐ ์ถ๋ ฅ
@Override
public ArrayList<BoardDTO> search( int currentPage, int numberPerPage, int searchCondition, String searchWord) throws SQLException {
ArrayList<BoardDTO> list = null;
BoardDTO dto = null;
int begin = ( currentPage-1)*numberPerPage + 1;
int end = begin + numberPerPage -1;
String sql =
" SELECT b.* "
+ " FROM ( "
+ " SELECT ROWNUM no, t.* "
+ " FROM ( "
+ " SELECT seq, writer, email, title, readed, writedate "
+ " FROM tbl_cstvsboard ";
switch (searchCondition) {
case 1: // ์ ๋ชฉ
sql += " WHERE REGEXP_LIKE( title , ? , 'i' ) ";
break;
case 2: // ๋ด์ฉ
sql += " WHERE REGEXP_LIKE( content , ? , 'i' ) ";
break;
case 3: // ์์ฑ์
sql += " WHERE REGEXP_LIKE( writer , ? , 'i' ) ";
break;
case 4: // ์ ๋ชฉ + ๋ด์ฉ
sql += " WHERE REGEXP_LIKE( title , ? , 'i' ) OR REGEXP_LIKE( content , ? , 'i' ) ";
break;
}
sql += " ORDER BY seq DESC "
+ " ) t "
+ " ) b "
+ " WHERE b.no BETWEEN ? AND ?";
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setString(1, searchWord );
if ( searchCondition == 4) {
this.pstmt.setString(2, searchWord );
this.pstmt.setInt(3, begin);
this.pstmt.setInt(4, end);
} else {
// BETWEEN ? AND ?"
this.pstmt.setInt(2, begin);
this.pstmt.setInt(3, end);
}
this.rs = this.pstmt.executeQuery();
// int no, seq, readed;
// String writer, email, title;
// Date writedate;
if ( this.rs.next()) {
list = new ArrayList<BoardDTO>();
do {
dto = new BoardDTO();
dto.setSeq(this.rs.getInt("seq"));
dto.setReaded(this.rs.getInt("readed"));
dto.setWriter( this.rs.getString("writer"));
dto.setEmail( this.rs.getString("email"));
if( searchCondition == 1 ) { // ์ ๋ชฉ ๊ฒ์
String title = this.rs.getString("title").replace(searchWord, "["+searchWord +"]");
dto.setTitle( title );
} else {
dto.setTitle( this.rs.getString("title"));
}
dto.setWritedate(this.rs.getDate("writedate"));
list.add(dto);
} while ( this.rs.next() );
} // if
this.rs.close(); //
this.pstmt.close();
return list; // ๊ฒ์๊ธ์ด ์กด์ฌํ์ง ์์ผ๋ฉด list = null ..
}
2) DAO Impl ํ ์คํธ
3) Service
public ArrayList<BoardDTO> searchService( int currentPage, int numberPerPage, int searchCondition, String searchWord) {
ArrayList<BoardDTO> list = null;
try {
// 1. ๋ก๊ทธ ๊ธฐ๋ก
// 2.
// 3.
list = this.dao.search( currentPage, numberPerPage, searchCondition, searchWord);
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
4) Service ํ ์คํธ
5) Controller
private int currentPage = 1; // ๋ชฉ๋ก ๋ณด๊ณ ์๋ ํ์ฌ ํ์ด์ง.
private int numberPerPage = 10; // ํ ํ์ด์ง์ ์ถ๋ ฅํ ๊ฒ์๊ธ ์
private int numberOfPageBlock = 10; // 1 2 3 4 5 6 7 8 9 10
private void ๊ฒ์ํ๊ธฐ() {
// 1. ์ ๋ชฉ 1 , ์์ฑ์ 2, ๋ด์ฉ 3 , ์ ๋ชฉ + ๋ด์ฉ 4 ๊ฒ์์กฐ๊ฑด ์
๋ ฅ
// 2. ๊ฒ์์ด ์
๋ ฅ
System.out.print("> ๊ฒ์๋ ํ์ฌ ํ์ด์ง( currentPage) ์
๋ ฅ ? " );
this.currentPage = this.scanner.nextInt();
int searchCondition; // ๊ฒ์์กฐ๊ฑด
System.out.print("> ๊ฒ์ ์กฐ๊ฑด : ์ ๋ชฉ(1) , ๋ด์ฉ(2), ์์ฑ์(3), ์ ๋ชฉ+๋ด์ฉ(4) ์ ํ ? ");
searchCondition = this.scanner.nextInt();
this.scanner.nextLine(); // 13,10
System.out.print("> ๊ฒ์์ด ์
๋ ฅ ? ");
String searchWord = this.scanner.nextLine();
ArrayList<BoardDTO> list = this.service.searchService(
currentPage, numberPerPage , searchCondition, searchWord);
// ๋ชฉ๋ก๋ณด๊ธฐ() ์ฝ๋ฉ ๋ณต์ฌ ๋ถ์ด๊ธฐ
System.out.println("\t\t\t ๊ฒ์ํ");
System.out.println("--------------------------------------------------------------");
System.out.printf("%s\t%-40s\t%s\t%-10s\t%s\n",
"๊ธ๋ฒํธ","๊ธ์ ๋ชฉ","๊ธ์ด์ด","์์ฑ์ผ","์กฐํ์");
System.out.println("--------------------------------------------------------------");
if ( list == null) {
System.out.println("\t\t ๊ฒ์๋ ๊ฒ์๊ธ ์กด์ฌ X ");
} else {
Iterator<BoardDTO> ir =list.iterator();
while (ir.hasNext()) {
BoardDTO dto = ir.next();
System.out.printf("%d\t%-30s %s\t%-10s\t%d\n",
dto.getSeq()
, dto.getTitle()
, dto.getWriter()
, dto.getWritedate()
, dto.getReaded()
);
}
} // if
System.out.println("--------------------------------------------------------------");
// System.out.println("\t\t\t [1] 2 3 4 5 6 7 8 9 10 >"); // ํ์ด์ง๋ธ๋ญ
// ๋ชฉ๋ก๋ณด๊ธฐ์ ํ์ด์ง ์ฒ๋ฆฌ ๋ถ๋ถ์ ์ฐธ์กฐํ๋ฉด ์์ ...
String pagingBlock = this.service.pagingService(
this.currentPage
, this.numberPerPage
, this.numberOfPageBlock
, searchCondition // ๊ฒ์์กฐ๊ฑด
, searchWord // ๊ฒ์์ด
);
System.out.println(pagingBlock);
System.out.println("--------------------------------------------------------------");
์ผ์์ ์ง();
}
[7. ํ์ด์ง ์ฒ๋ฆฌ1 - ๋ชฉ๋ก๋ณด๊ธฐ]
1) ์ด ๋ ์ฝ๋ ์ ํ์
2) ํ ํ์ด์ง์ ๋ช ๊ฐ ๋ ์ฝ๋ ์ 3) ์ด ํ์ด์ง = ์ด ๋ ์ฝ๋ / ํ ํ์ด์ง ๋ ์ฝ๋ ์ (์ฌ๋ฆผ) 4) ํ์ฌ ํ์ด์ง 5) ํ์ด์ง ๋ธ๋ญ ์ (1~10๊น์ง) 6) ์์ ๋ธ๋ญ (1) 7) ๋ ๋ธ๋ญ (10) 8) prev < ์ด์ , next > ๋ค์ ํ์ ์ฌ๋ถ |
1) DAO Impl
@Override
public int getTotalRecords() throws SQLException {
int totalRecords = 0;
String sql = "SELECT COUNT(*) "
+ " FROM tbl_cstvsboard ";
this.pstmt = this.conn.prepareStatement(sql);
this.rs = this.pstmt.executeQuery() ;
if( rs.next() ) {
totalRecords = rs.getInt( 1 );
}
this.pstmt.close();
this.rs.close();
return totalRecords;
}
@Override
public int getTotalPages(int numberPerPage) throws SQLException {
int totalPages = 0;
String sql = "SELECT CEIL(COUNT(*)/?) "
+ " FROM tbl_cstvsboard ";
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setInt(1, numberPerPage) ;
this.rs = this.pstmt.executeQuery() ;
if( rs.next() ) {
totalPages = rs.getInt( 1 );
}
this.pstmt.close();
this.rs.close();
return totalPages;
}
2) DAO Impl ํ ์คํธ
@Test
void getTotalRecords_test() {
Connection conn = DBConn.getConnection();
BoardDAOImpl dao = new BoardDAOImpl(conn);
try {
// int totalRecords = dao.getTotalRecords();
// System.out.println( totalRecords );
int totalPages = dao.getTotalPages( 10 );
System.out.println( totalPages );
} catch (SQLException e) {
e.printStackTrace();
}
DBConn.close();
}
3) Service
// "\t\t\t [1] 2 3 4 5 6 7 8 9 10 >"
public String pagingService(int currentPage, int numberPerPage, int numberOfPageBlock) {
String pagingBlock = "\t\t\t";
try {
int totalRecords = this.dao.getTotalRecords() ;
// int totalPages = totalRecords / numberPerPage + 1 ;
int totalPages = this.dao.getTotalPages( numberPerPage ) ;
int begin = ( currentPage - 1)/numberOfPageBlock * numberOfPageBlock + 1;
int end = begin + numberOfPageBlock - 1;
if( end > totalPages ) end = totalPages;
boolean prev = begin == 1 ? false : true;
boolean next = end == totalPages ? false: true;
if(prev) pagingBlock +=" < " ;
for (int j = begin; j <= end; j++) {
pagingBlock += String.format( currentPage == j ? " [%d]" : " %d ", j) ;
}
if( next ) pagingBlock +=" > " ;
} catch( SQLException e) {
e.printStackTrace();
}
return pagingBlock;
}
4) Service ํ ์คํธ
5) Controller
private void ๋ชฉ๋ก๋ณด๊ธฐ() {
// 357 INSERT
// BoardService.selectService()/ BoardDAO.select()
System.out.print("> ํ์ฌ ํ์ด์ง( currentPage) ์
๋ ฅ ? " );
this.currentPage = this.scanner.nextInt();
this.scanner.nextLine(); // 13,10
ArrayList<BoardDTO> list = this.service.selectService(this.currentPage, this.numberPerPage);
// M[V]C - ์ถ๋ ฅ ๋ด๋น ๋ทฐ.
System.out.println("\t\t\t ๊ฒ์ํ");
System.out.println("--------------------------------------------------------------");
System.out.printf("%s\t%-40s\t%s\t%-10s\t%s\n",
"๊ธ๋ฒํธ","๊ธ์ ๋ชฉ","๊ธ์ด์ด","์์ฑ์ผ","์กฐํ์");
System.out.println("--------------------------------------------------------------");
if ( list == null) {
System.out.println("\t\t ๊ฒ์๊ธ ์กด์ฌ X ");
} else {
Iterator<BoardDTO> ir =list.iterator();
while (ir.hasNext()) {
BoardDTO dto = ir.next();
System.out.printf("%d\t%-30s %s\t%-10s\t%d\n",
dto.getSeq()
, dto.getTitle()
, dto.getWriter()
, dto.getWritedate()
, dto.getReaded()
);
}// if
System.out.println("--------------------------------------------------------------");
// System.out.println("\t\t\t [1] 2 3 4 5 6 7 8 9 10 >"); // ํ์ด์ง๋ธ๋ญ
String pagingBlock = this.service.pagingService(
this.currentPage
, this.numberPerPage
, this.numberOfPageBlock
);
System.out.println(pagingBlock);
System.out.println("--------------------------------------------------------------");
์ผ์์ ์ง();
}
[7. ํ์ด์ง ์ฒ๋ฆฌ2 - ๊ฒ์๊ฒฐ๊ณผ]
1) ์ด ๋ ์ฝ๋ ์ ํ์
2) ํ ํ์ด์ง์ ๋ช ๊ฐ ๋ ์ฝ๋ ์ 3) ์ด ํ์ด์ง = ์ด ๋ ์ฝ๋ / ํ ํ์ด์ง ๋ ์ฝ๋ ์ (์ฌ๋ฆผ) 4) ํ์ฌ ํ์ด์ง 5) ํ์ด์ง ๋ธ๋ญ ์ (1~10๊น์ง) 6) ์์ ๋ธ๋ญ (1) 7) ๋ ๋ธ๋ญ (10) 8) prev < ์ด์ , next > ๋ค์ ํ์ ์ฌ๋ถ |
1) DAO Impl
// ๊ฒ์ํ๊ธฐ
@Override
public int getTotalRecords(int searchCondition, String searchWord) throws SQLException {
int totalRecords = 0;
String sql = "SELECT COUNT(*) "
+ " FROM tbl_cstvsboard ";
switch (searchCondition) {
case 1: // ์ ๋ชฉ
sql += " WHERE REGEXP_LIKE( title , ? , 'i' ) ";
break;
case 2: // ๋ด์ฉ
sql += " WHERE REGEXP_LIKE( content , ? , 'i' ) ";
break;
case 3: // ์์ฑ์
sql += " WHERE REGEXP_LIKE( writer , ? , 'i' ) ";
break;
case 4: // ์ ๋ชฉ + ๋ด์ฉ
sql += " WHERE REGEXP_LIKE( title , ? , 'i' ) OR REGEXP_LIKE( content , ? , 'i' ) ";
break;
}
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setString(1, searchWord);
if ( searchCondition == 4 ) {
this.pstmt.setString(2, searchWord);
}
this.rs = this.pstmt.executeQuery() ;
if( rs.next() ) {
totalRecords = rs.getInt( 1 );
}
this.pstmt.close();
this.rs.close();
return totalRecords;
}
// ๋จ์ ํ
์คํธ
@Override
public int getTotalPages(int numberPerPage,int searchCondition, String searchWord) throws SQLException {
int totalPages = 0;
String sql = "SELECT CEIL(COUNT(*)/?) "
+ " FROM tbl_cstvsboard ";
switch (searchCondition) {
case 1: // ์ ๋ชฉ
sql += " WHERE REGEXP_LIKE( title , ? , 'i' ) ";
break;
case 2: // ๋ด์ฉ
sql += " WHERE REGEXP_LIKE( content , ? , 'i' ) ";
break;
case 3: // ์์ฑ์
sql += " WHERE REGEXP_LIKE( writer , ? , 'i' ) ";
break;
case 4: // ์ ๋ชฉ + ๋ด์ฉ
sql += " WHERE REGEXP_LIKE( title , ? , 'i' ) OR REGEXP_LIKE( content , ? , 'i' ) ";
break;
}
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setInt(1, numberPerPage) ;
this.pstmt.setString(2, searchWord);
if( searchCondition == 4 ) this.pstmt.setString(3, searchWord);
this.rs = this.pstmt.executeQuery() ;
if( rs.next() ) {
totalPages = rs.getInt( 1 );
}
this.pstmt.close();
this.rs.close();
return totalPages;
}
2) DAO Impl ํ ์คํธ
3) Service
// ๊ฒ์ํ๊ธฐ - ํ์ด์ง์ฒ๋ฆฌ ๋ฉ์๋
public String pagingService(int currentPage, int numberPerPage, int numberOfPageBlock
, int searchCondition, String searchWord) {
String pagingBlock = "\t\t\t";
try {
int totalRecords = this.dao.getTotalRecords(searchCondition, searchWord) ;
// int totalPages = totalRecords / numberPerPage + 1 ;
int totalPages = this.dao.getTotalPages( numberPerPage , searchCondition, searchWord) ;
int begin = ( currentPage - 1)/numberOfPageBlock * numberOfPageBlock + 1;
int end = begin + numberOfPageBlock - 1;
if( end > totalPages ) end = totalPages;
boolean prev = begin == 1 ? false : true;
boolean next = end == totalPages ? false: true;
if(prev) pagingBlock +=" < " ;
for (int j = begin; j <= end; j++) {
pagingBlock += String.format( currentPage == j ? " [%d]" : " %d ", j) ;
}
if( next ) pagingBlock +=" > " ;
} catch( SQLException e) {
e.printStackTrace();
}
return pagingBlock;
}
4) Service ํ ์คํธ
5) Controller
private void ๊ฒ์ํ๊ธฐ() {
// 1. ์ ๋ชฉ 1 , ์์ฑ์ 2, ๋ด์ฉ 3 , ์ ๋ชฉ + ๋ด์ฉ 4 ๊ฒ์์กฐ๊ฑด ์
๋ ฅ
// 2. ๊ฒ์์ด ์
๋ ฅ
System.out.print("> ๊ฒ์๋ ํ์ฌ ํ์ด์ง( currentPage) ์
๋ ฅ ? " );
this.currentPage = this.scanner.nextInt();
int searchCondition; // ๊ฒ์์กฐ๊ฑด
System.out.print("> ๊ฒ์ ์กฐ๊ฑด : ์ ๋ชฉ(1) , ๋ด์ฉ(2), ์์ฑ์(3), ์ ๋ชฉ+๋ด์ฉ(4) ์ ํ ? ");
searchCondition = this.scanner.nextInt();
this.scanner.nextLine(); // 13,10
System.out.print("> ๊ฒ์์ด ์
๋ ฅ ? ");
String searchWord = this.scanner.nextLine();
ArrayList<BoardDTO> list = this.service.searchService(
currentPage, numberPerPage , searchCondition, searchWord);
// ๋ชฉ๋ก๋ณด๊ธฐ() ์ฝ๋ฉ ๋ณต์ฌ ๋ถ์ด๊ธฐ
System.out.println("\t\t\t ๊ฒ์ํ");
System.out.println("--------------------------------------------------------------");
System.out.printf("%s\t%-40s\t%s\t%-10s\t%s\n",
"๊ธ๋ฒํธ","๊ธ์ ๋ชฉ","๊ธ์ด์ด","์์ฑ์ผ","์กฐํ์");
System.out.println("--------------------------------------------------------------");
if ( list == null) {
System.out.println("\t\t ๊ฒ์๋ ๊ฒ์๊ธ ์กด์ฌ X ");
} else {
Iterator<BoardDTO> ir =list.iterator();
while (ir.hasNext()) {
BoardDTO dto = ir.next();
System.out.printf("%d\t%-30s %s\t%-10s\t%d\n",
dto.getSeq()
, dto.getTitle()
, dto.getWriter()
, dto.getWritedate()
, dto.getReaded()
);
}
} // if
System.out.println("--------------------------------------------------------------");
// System.out.println("\t\t\t [1] 2 3 4 5 6 7 8 9 10 >"); // ํ์ด์ง๋ธ๋ญ
// ๋ชฉ๋ก๋ณด๊ธฐ์ ํ์ด์ง ์ฒ๋ฆฌ ๋ถ๋ถ์ ์ฐธ์กฐํ๋ฉด ์์ ...
String pagingBlock = this.service.pagingService(
this.currentPage
, this.numberPerPage
, this.numberOfPageBlock
, searchCondition // ๊ฒ์์กฐ๊ฑด
, searchWord // ๊ฒ์์ด
);
System.out.println(pagingBlock);
System.out.println("--------------------------------------------------------------");
์ผ์์ ์ง();
}
๊ณ์์ฌ๋ถํ์ธ Controller
// days02.Ex02_02.java
private static char _continue = 'y';
private static void ๊ณ์์ฌ๋ถํ์ธ() {
System.out.print("> ๊ณ์ ํ ๊ฑฐ๋ ? ");
try {
_continue = (char)System.in.read();
System.in.skip( System.in.available() ); // 13, 10 ์ ๊ฑฐ
} catch (IOException e) {
e.printStackTrace();
}
}
'๐จโ๐ป Web Development > JDBC | JSP | Servlet' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Day1] JSP/Servlet 1 - ๊ฐ์ (0) | 2022.12.06 |
---|---|
[Day5] JSP/JDBC 5 - transaction ์ฒ๋ฆฌ, callable statement, reflection (0) | 2022.11.02 |
[Day3] JSP/JDBC 3 - ์ฌ์ฉ์ ๋ณ๊ฒฝ, ์ฌ๋ฌ์ถ๋ ฅ๋ฐฉ์, linkedhashmap์ฌ์ฉ DTO ์ ์ฅ, MVC, JUnit (0) | 2022.10.31 |
[Day2] JSP/JDBC 2 - ๋์ ์ฟผ๋ฆฌ, PreparedStatement (0) | 2022.10.31 |
[Day1] JSP/JDBC 1 - ๊ฐ์, jdbc driver, dto (0) | 2022.10.28 |
์ต๊ทผ๋๊ธ