package test.com.board;
public class BoardVO {
private int num;
private String title;
private String name;
private String content;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Override
public String toString() {
return "BoardVO [num=" + num + ", title=" + title + ", name=" + name + ", content=" + content + "]";
}
}
게시판에 나타낼 요소들: num, title, name, content
package test.com.board;
import java.util.ArrayList;
public class BoardDAO {
public int insert(BoardVO vo) {
System.out.println("insert()...");
System.out.println(vo);
return 1;
}
public int delete(BoardVO vo) {
System.out.println("delete()...");
System.out.println(vo);
return 1;
}
public int update(BoardVO vo) {
System.out.println("update()...");
System.out.println(vo);
return 1;
}
public BoardVO selectOne(BoardVO vo) {
System.out.println("selectOne()...");
System.out.println(vo);
BoardVO bvo = new BoardVO();
bvo.setNum(vo.getNum());
bvo.setTitle("BBB");
bvo.setName("kim");
bvo.setContent("Banana");
return bvo;
}
public ArrayList<BoardVO> selectAll(){
System.out.println("selectAll()...");
ArrayList<BoardVO> vos = new ArrayList<BoardVO>();
for (int i = 0; i < 30; i++) {
BoardVO vo = new BoardVO();
vo.setNum(i);
vo.setTitle("CCC"+i);
vo.setName("lee"+i);
vo.setContent("Cherry"+i);
vos.add(vo);
}
return vos;
}
}
앞서 VO로 정의한 게시판 요소를 저장하는 DAO
package test.com.board;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class BoardController
*/
@WebServlet({ "/index.do", "/insertForm.do", "/selectOne.do", "/selectAll.do" })
public class BoardController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public BoardController() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// response.getWriter().append("Served at: ").append(request.getContextPath());
if(request.getServletPath().equals("/index.do")) {
request.getRequestDispatcher("index.jsp").forward(request,response);
}else if(request.getServletPath().equals("/insertForm.do")) {
request.getRequestDispatcher("insertForm.jsp").forward(request,response);
}else if(request.getServletPath().equals("/selectOne.do")) {
}else if(request.getServletPath().equals("/selectAll.do")) {
request.getRequestDispatcher("selectAll.jsp").forward(request,response);
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}