본문 바로가기
프로젝트/Summernote를 활용한 WYSIWYG 게시판 만들기

6. 조회하기

by IT여행자 2023. 1. 1.
728x90

특별한 UI나 기능을 모두 제외하고 단지 제목으로 검색이 되도록 작성하였습니다.

 

 

package bean;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SnDao {
	String uploadPath = "N:\\workspace\\summernote\\src\\main\\webapp\\";
	Connection conn;
	PreparedStatement ps;
	ResultSet rs;
	String sql;
	public SnDao() {
		try {
			conn = new DBConn().getConn();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public List<SnVo> select(String findStr) {
		List<SnVo> list = new ArrayList<SnVo>();
		sql = "select * from summernote where subject like ? order by serial desc";
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, "%" + findStr + "%");
			rs = ps.executeQuery();

			while (rs.next()) {
				SnVo vo = new SnVo();
				vo.setSerial(rs.getInt("serial"));
				vo.setSubject(rs.getString("subject"));

				list.add(vo);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		return list;

	}

}

 

1) 목록 페이지


단순히 제목(subject) 부분만을 페이징 처리 없이 나열하도록 하겠습니다.

 

<%@page import="bean.SnVo"%>
<%@page import="java.util.List"%>
<%@page import="bean.SnDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel='stylesheet' type='text/css' href='./css/sn.css'>
</head>
<body>
	<%
		String findStr = "";
		if(request.getParameter("findStr") != null){
			findStr = request.getParameter("findStr");	
		}
		
		SnDao dao = new SnDao();
		List<SnVo> list = dao.select(findStr);
	
	%>

	<div id='list'>
		<h2>LIST</h2>
		<form name='frm_search' id='frm_search' method='post'>
			<a href='insert.jsp'>입력</a>
			<input type='search' name='findStr' value='<%=findStr%>'/>
			<input type='submit' value='검색' id='btnSearch'/>
		</form>

		<div id='items'>
			
			<div id='title'>
				<span class='subject'>제 목</span>
			</div>
			
				<%for(SnVo vo : list){ %>
					<div class='item'>
						<a href='view.jsp?serial=<%=vo.getSerial()%>'>
							<span><%=vo.getSubject() %></span>
						</a>
					</div>
				<%} %>					
				<hr/>
		</div>

	</div>

</body>
</html>

 

'프로젝트 > Summernote를 활용한 WYSIWYG 게시판 만들기' 카테고리의 다른 글

2. 기본 구조  (0) 2023.01.01
3. 에디터 화면 및 저장 만들기  (0) 2023.01.01
4. 수정하기  (0) 2023.01.01
5. 삭제하기  (0) 2023.01.01
7. 상세보기  (0) 2023.01.01