<BoardDAO.java>
package com.smhrd.model;
import java.util.ArrayList;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import com.smhrd.database.SqlSessionManager;
public class BoardDAO {
private SqlSessionFactory sqlSessionFactory = SqlSessionManager.getSqlSession();
private SqlSession sqlSession = null;
// 파일업로드 메소드
public int upload(BoardVO vo) {
int row = 0;
try {
sqlSession = sqlSessionFactory.openSession(true);
row = sqlSession.insert("com.smhrd.model.BoardDAO.boardinsert",vo);
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return row;
}
// 게시글 목록 조회 메소드
@SuppressWarnings({"unchecked","rawtypes"})
public ArrayList<BoardVO> showBoard() {
ArrayList<BoardVO> list = new ArrayList<BoardVO>();
try {
sqlSession = sqlSessionFactory.openSession(true);
list = (ArrayList) sqlSession.selectList("com.smhrd.model.BoardDAO.boardselect");
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return list;
}
}
<BoardMapper.xml>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.smhrd.model.BoardDAO" >
<insert id="boardinsert" parameterType="BoardVO">
insert into messageboard values(num_board.nextval, #{title}, #{writer}, #{fileName}, #{content}, sysdate)
</insert>
<select id="boardselect" resultType="BoardVO">
select * from messageboard order by b_day desc
</select>
</mapper>
<boardMain.jsp>
<%@page import="com.smhrd.model.BoardDAO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.smhrd.model.BoardVO"%>
<%@ 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>
<title>Forty by HTML5 UP</title>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
<link rel="stylesheet" href="assetsBoard/css/main.css" />
<link rel="stylesheet" href="assetsBoard/css/board.css" />
<!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
<!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
</head>
<body>
<%
BoardDAO dao = new BoardDAO();
ArrayList<BoardVO> list = dao.showBoard();
%>
<div id="board">
<table id = "list">
<tr>
<td>번호</td>
<td>제목</td>
<td>작성자</td>
<td>시간</td>
</tr>
<%for(int i=0; i<list.size();i++) {%>
<tr>
<td><%= i+1 %></td>
<td><%= list.get(i).getTitle() %></td>
<td><%= list.get(i).getWriter() %></td>
<td><%= list.get(i).getB_day() %></td>
</tr>
<%} %>
</table>
<a href="main.jsp"><button id="writer">홈으로가기</button></a>
<a href="writerBoard.jsp"><button id="writer">작성하러가기</button></a>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.js"></script>
</body>
</html>
'Maven Project' 카테고리의 다른 글
게시판 글 삭제 (0) | 2022.05.27 |
---|---|
게시판 세부내용 (0) | 2022.05.27 |
게시판 삭제, 게시판 글 수정 (0) | 2022.05.26 |
<게시판 - 파일 업로드 실습> (0) | 2022.05.26 |
게시판 만들기 (0) | 2022.05.25 |