반응형
JAVA
DBConnection
package com.coffee.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection {
public Connection getConn() { // 커넥션을 반환해줌
Connection connection = null;
try {
Class.forName("org.mariadb.jdbc.Driver");
final String url = " ";
final String user = " ";
final String pw = " "; // final로 수정 불가하도록
connection = DriverManager.getConnection(url, user, pw);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
}
DTO (Data Transfer Object)
package com.coffee.dto;
public class BoardDTO {
private String board_title, board_write, board_date;
private int board_no, board_count;
// getter setter
public String getBoard_title() {
return board_title;
}
public void setBoard_title(String board_title) {
this.board_title = board_title;
}
public String getBoard_write() {
return board_write;
}
public void setBoard_write(String board_write) {
this.board_write = board_write;
}
public String getBoard_date() {
return board_date;
}
public void setBoard_date(String board_date) {
this.board_date = board_date;
}
public int getBoard_no() {
return board_no;
}
public void setBoard_no(int board_no) {
this.board_no = board_no;
}
public int getBoard_count() {
return board_count;
}
public void setBoard_count(int board_count) {
this.board_count = board_count;
}
}
DAO (Data Access Object)
package com.coffee.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//데이터 접속 객체 (Data Access Object)
import com.coffee.db.DBConnection;
import com.coffee.dto.BoardDTO;
public class BoardDAO {
DBConnection dbConn = new DBConnection();
public List<BoardDTO> boardList () {
List<BoardDTO> list = new ArrayList<BoardDTO>();
Connection con = dbConn.getConn();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM board";
try {
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
list = new ArrayList<BoardDTO>();
while (rs.next()) {
BoardDTO dto = new BoardDTO();
dto.setBoard_no(rs.getInt(1));
dto.setBoard_title(rs.getString(2));
dto.setBoard_write(rs.getString(3));
dto.setBoard_date(rs.getString(4));
dto.setBoard_count(rs.getInt(5));
list.add(dto);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
rs.close();
pstmt.close();
con.close();
} catch (SQLException e) {
}
}
return list;
}
}
jsp
index
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>--- 오늘 할 것 ---</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Gowun+Dodum&display=swap" rel="stylesheet">
</head>
<body style="background: linear-gradient(135deg, #D0B0FF, #FF857D); font-family: Gowun Dodum; font-size: 18pt">
<!-- 목록 태그 -->
<h1 style="color: white">2023년 12월 28일 목요일입니다.</h1>
<ol type="1" reversed="reversed" start="5">
<li>팀 뽑기 웹버전 만들기</li>
<li>html/css/js</li>
<li>시험보기~</li><br><br>
<li>li = list item 목록만들기 </li>
<li> ol type : type 어떤 형태로 리스트 만들지~ </li>
<li> reversed 순서를 거꾸로 매기기 </li>
</ol>
<ul type="square">
<li style="font-size: 20pt">ul = unordered line</li>
<li>번호리스트 없이 작은 동그라미로 순서 매김(square, circle)</li>
<li>Let me go home</li>
<li></li>
</ul>
<img alt="이미지가 없습니다." src="https://i.pinimg.com/564x/f9/e5/c1/f9e5c19d2a51bda108e5ea536d7745c1.jpg">
<img alt"" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQZsvQbKj0ObvAmWByV5wgvL6WIhItqIAJwiQ&usqp=CAU" width=600px height=500px><br>
<img src="https://img2.quasarzone.com/editor/2021/04/16/ce45a3904d45602e9271221376e43f6d.jpg" width=500px height=500px>
<img src="https://outstanding.kr/wp-content/uploads/2018/02/%EB%8B%A4%EC%9A%B4%EB%A1%9C%EB%93%9C-2.jpg"><br>
<img src="https://pbs.twimg.com/media/CjYClkSVEAAAAud.jpg">
<img alt="" src="./img.png" width=500px height=300px><br>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQf_Fc2FxnR7zB60Uyztv9I8UwE_BOYrpMwONAQjvPfLx2GMn1rzZFwxmgb5U8wLY7dDPs&usqp=CAU">
<hr>
지금 스페이스바 10칸 쳤습니다. 스페이스가 적용 안됨.<br>
지금 스페이스바 5칸 쳤습니당.<br>
& n b s p ; = 스페이스 한번 <br>
<hr>
<ol>
<li>조합형 한글 / 완성형 한글</li>
<li>아스키코드</li>
<li>eur-kr / UTF-8 차이</li>
<li>윈도우에서 사용하는 언어셋?</li>
<li>유니코드</li>
<li></li>
</ol>
<a href="./main.jsp">main</a>
</body>
</html>
main
<%@page import="java.util.List"%>
<%@page import="com.coffee.team.Team"%>
<%@ 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>
</head>
<body>
<!-- 5팀 팀뽑기를 만들어주세요. -->
<%
Team teamClass = new Team();
List<List<String>> team = teamClass.getTeam();
%>
<%
for (List<String> list : team) {
for(String str : list){
//여기는 자바 69804
%>
<!-- 여기는 html -->
<%=str%>
<%
}
%>
<br>
<%
}
//여기도 자바
%>
<a href="./board.jsp">board</a>
</body>
</html>
board
<%@page import="com.coffee.dto.BoardDTO"%>
<%@page import="java.util.List"%>
<%@page import="com.coffee.dao.BoardDAO"%>
<%@ 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>
<style type="text/css">
/* 스타일 sheet
html 태그 {
속성 : 값;
}*/
body {
background-color: #8A68FF;
}
h1, h2 {
color: white;
font-weight: bold;
font-family: Gowun Dodum;
}
/* id는 앞에 # 붙이기, class는 . 붙이기 */
#head3 {
color: gold;
text-decoration: underline;
}
.head3 {
background-color: #FF68A1;
text-align: center;
}
#board {
width: 70%;
height: 500px;
background-color: #FFF9D9;
border-collapse: collapse; /*공백 없이 붙이기*/
}
td {
border-bottom: 1px solid gray; /* solid 실선, dotted 점선 */
text-align: center;
}
/*
tr:nth-child(even){ even 짝수, odd 홀수 줄 색상 변경
background-color: #E0FFD9;
}
*/
.w1 {
width: 10%;
}
.w2 {
width: 20%;
}
.w5 {
width: 50%;
text-align: left;
}
tr:hover { /* tr 한 줄 지정시 컬러, td 한 칸씩 컬러 지정 */
background-color: #AC86EC;
color: white;
}
</style>
</head>
<body>
<!-- 데이터베이스에서 가져오기 -->
<%
BoardDAO dao = new BoardDAO();
List<BoardDTO> list = dao.boardList();
%>
<!-- 10개 글 가져오기 -->
<!-- 번호, 제목, 글쓴이, 작성일, 조회수 -->
<h1>게시판 환영합니다</h1>
<h2 class="head3">게시판2</h2>
<h3 id="head3">게시판3</h3>
<table id="board">
<tr style="background-color: #FFE456">
<th>번호</th>
<th>제목</th>
<th>글쓴이</th>
<th>날짜</th>
<th>조회수</th>
</tr>
<%
for(BoardDTO dto : list) {
%>
<tr>
<td class="w1"><%=dto.getBoard_no()%></td>
<td class="w5"><%=dto.getBoard_title()%></td>
<td class="w1"><%=dto.getBoard_write()%></td>
<td class="w2"><%=dto.getBoard_date()%></td>
<td class="w1"><%=dto.getBoard_count()%></td>
<%
}
%>
</tr>
</table>
</body>
</html>
반응형
'개발 공부 Today I Learned' 카테고리의 다른 글
[국비 29일차 TIL] 게시판 만들기 2 (글 저장, 글 수정) (0) | 2024.01.02 |
---|---|
[국비 28일차 TIL] 게시판 만들기 1 (게시글 작성 페이지, 삭제 등) (1) | 2023.12.29 |
[국비 26일차 TIL] JSP 프로젝트 생성, 데이터베이스 연결 (0) | 2023.12.27 |
[국비 25일차 TIL] JAVA 예외 처리, try catch finally (1) | 2023.12.27 |
[국비 24일차 TIL] Collection, List, Set, Map (2) | 2023.12.22 |
댓글