[๊ตฌ๋์์นด๋ฐ๋ฏธ IT๊ตญ๋น์ง์] SELECT๋ฌธ์ ORDER BY์ ๊ณผ WHERE์ ์ ์ด์ฉํ์ฌ ์ ๋ ฌ ๊ธฐ๋ฅ๊ณผ ์ฑ๋ณ ๊ฒ์๊ธฐ๋ฅ์ ๊ตฌํํ๋ ๋ฒ์ ๋ํด ๋ฐฐ์ ๋ค.
์๋์ฐ์ฐฝ์์ mariadb cmd ์ฐฝ์ ์คํ์ํจ๋ค.
๋ก๊ทธ์ธ ํ ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅ
show databases; ๋ก ๋ฐ์ดํฐ ๋ฒ ์ด์ค ๋ชฉ๋ก์ ํ์ธํ ์ ์๋ค.
use ๋ช ๋ น์ด๋ก ๋ฐ์ดํฐ ๋ฒ ์ด์ค๋ฅผ ์ ํํ๊ณ , show tables;๋ฅผ ์ ๋ ฅํ๋ฉด ํด๋น ๋ฐ์ดํฐ ๋ฒ ์ด์ค์ ํ ์ด๋ธ ๋ชฉ๋ก์ ๋ณผ ์ ์๋ค.
desc ๋ฅผ ์ ๋ ฅํ๋ฉด ํด๋น ํ ์ด๋ธ์ ์กฐํํ ์ ์๋ค.
mariadb์ ์ ๋ ฅํ๋ ์ฟผ๋ฆฌ๋ฅผ ๊ทธ๋๋ก ์ ๋ ฅํด์ ๋๊ฐ์ด ์คํํ ์ ์๋ค!
cd ๋ช
๋ น์ด๋ก ์ค์นํ ์ํDB ํ์ผ์ ์์น๋ก ์ด๋ํ๋ค
(ex. cd c:\employees)
์ด๋ ํ mysql -u ๊ณ์ ์ด๋ฆ -p ์ ๋ ฅ ํ ๋น๋ฐ๋ฒํธ๋ ์ ๋ ฅํ์ฌ ๋ก๊ทธ์ธ
source ํ์ผ๋ช ์ผ๋ก ์ค์นํ๋ค. (ex. source employees.sql)
HeidiSQL๋ฅผ ์คํํด๋ณด๋ฉด ์ ์์ ์ผ๋ก ๋ฐ์ดํฐ ๋ฒ ์ด์ค๊ฐ ์ค์น๋ ๊ฒ์ ํ์ธํ ์ ์๋ค!
select๋ฌธ์ order by์ ์ ์ด์ฉํ์ฌ ๊ฐ ์ปฌ๋ผ์ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์, ๋ด๋ฆผ์ฐจ์์ ๋ณ๊ฒฝํ ์ ์๋ ๋ฐฉ๋ฒ์ ๋ํด ๋ฐฐ์ ๋ค.
์ฐธ๊ณ ๋ก order by์ ์ ์๋ตํ ๊ฒฝ์ฐ ๊ธฐ๋ณธํค ์์ผ๋ก ์ค๋ฆ์ฐจ์(์์๊ฑฐ->ํฐ๊ฑฐ)์ผ๋ก ์ ๋ ฌ๋๋ค!
๐ ์์ฑ
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "vo.*" %>
<%
// ์ ๋ ฌ ๊ธฐ๋ฅ
// ํ์ฌํ์ด์ง ์์ฒญ๊ฐ ๊ฒ์ฌ
int curPage = 1; // ํ์ฌํ์ด์ง๋ 1๋ถํฐ ์์
if(request.getParameter("curPage") != null) { // ๋์ด์จ curPage๊ฐ null์ด๊ฑฐ๋ ๊ณต๋ฐฑ์ด ์๋ ๊ฒฝ์ฐ // ์ฆ, ์ด์ ๋๋ ๋ค์์ ๋๋ ์ ๊ฒฝ์ฐ
curPage = Integer.parseInt(request.getParameter("curPage")); // intํ์
์ผ๋ก ๊ฐ ๋ฐ๊ธฐ
}
System.out.println("ํ์ฌํ์ด์ง: " + curPage + "ํ์ด์ง");
// ํ์ด์ง๋น ์ถ๋ ฅํ ํ์ด ๋ช๊ฐ์ธ์ง
int rowPerPage = 10;
// ํ์ด์ง๋น ์์ ํ ๋ฒํธ๊ฐ ๋ช๋ฒ์ธ์ง
int startRow = (curPage - 1) * rowPerPage;
System.out.println("ํ์ฌ ์์ ํ๋ฒํธ: " + startRow + "๋ฒ");
/*
curPage startRow rowPerPage
1 0 30
2 30 30
3 60 30
4 90 30
*/
// 1) ๋๋ผ์ด๋ฒ ๋ก๋ฉ
Class.forName("org.mariadb.jdbc.Driver");
// 2) mariadb ์๋ฒ ์ ์
Connection conn = DriverManager.getConnection("jdbc:mariadb://127.0.0.1:3306/employees","****","****");
// 3) ์ฟผ๋ฆฌ ์์ฑ ํ ์คํ // ํด๋ฆญํ๋ฉด ์ ๋ ฌ์ด ๋ฐ๋ ์ ์๋๋ก ORDER BY ์ฌ์ฉ
/*
SELECT
emp_no empNo,
birth_date birthDate,
first_name firstName,
last_name lastName,
gender gender,
hire_date hireDate
FROM employees
ORDER BY emp_no ASC // ํด๋นํ๋ ์ปฌ๋ผ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ์ด ๊ณ์ ๋ฐ๋๊ฒ ํ๋ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๋ ค๋ฉด, emp_no ASC๊ฐ ๊ณ์ ๋ฐ๋์ด์ผํ๋๋ฐ ๊ฐ์ด ์๋๊ธฐ ๋๋ฌธ์ ?๋ก ๋ค์ด๊ฐ ์ ์๋ค
LIMIT ?, ?
*/
String col = "emp_no"; // ๊ทธ๋์ ๊ฐ๊ฐ ๋ณ์๋ก ๋๋ค
String ascDesc = "ASC"; // ๊ธฐ๋ณธ๊ฐ์ emp_no ASC
if(request.getParameter("col") != null // ๊ฐ์ด ๋์ด์์ ๊ฒฝ์ฐ ๊ทธ ๊ฐ์ ๋ฐ์์ค๋ค
&& request.getParameter("ascDesc") != null) {
col = request.getParameter("col");
ascDesc = request.getParameter("ascDesc");
} // ORDER BY " + col + " " + ascDesc + " LIMIT // spl ์์ฑํ ๋ ์ค๊ฐ์ ๊ณต๋ฐฑ๋ ์ ๋ฃ์ด์ฃผ์ด์ผํจ
String sql = "SELECT emp_no empNo, birth_date birthDate, first_name firstName, last_name lastName, gender gender, hire_date hireDate FROM employees ORDER BY " + col + " " + ascDesc + " LIMIT ?, ?";
PreparedStatement stmt = conn.prepareStatement(sql);
// ํ ํ์ด์ง๋น ๋ช๊ฐ์ฉ ์ถ๋ ฅํ ์ง limit ?,? ์ฌ์ฉ
// startRow๋ฒ๋ถํฐ rowPerPage๊ฐ์ฉ ์ถ๋ ฅ
stmt.setInt(1, startRow);
stmt.setInt(2, rowPerPage);
System.out.println("empList sql: " + stmt);
ResultSet rs = stmt.executeQuery();
// ResultSet -> ArrayList<Emp>
ArrayList<Emp> empList = new ArrayList<Emp>();
while(rs.next()) {
Emp e = new Emp();
e.empNo = rs.getInt("empNo");
e.birthDate = rs.getString("birthDate");
e.firstName = rs.getString("firstName");
e.lastName = rs.getString("lastName");
e.gender = rs.getString("gender");
e.hireDate = rs.getString("hireDate");
empList.add(e);
}
// ๋ฐ์ดํฐ๊ฐ ์ด ๋ชํ์ธ์ง ๊ตฌํ๊ธฐ count(*) ์ฌ์ฉ
String sql2 = "SELECT count(*) FROM employees";
PreparedStatement stmt2 = conn.prepareStatement(sql2);
ResultSet rs2 = stmt2.executeQuery();
System.out.println("empList sql2: " + stmt2);
// ResultSet -> int totalRow์ ๊ฐ์ ๋ฃ๋๋ค
int totalRow = 0;
if(rs2.next()) {
totalRow = rs2.getInt("count(*)");
}
System.out.println("์ ์ฒด ๋ฐ์ดํฐ ํ์ ์: ์ด " + totalRow + "๊ฐ");
// ์ด ์ถ๋ ฅ๋๋ ํ์ด์ง์ ์(๋ง์ง๋ง ํ์ด์ง ๋๋ฒ) ๊ตฌํ๊ธฐ
int lastPage = totalRow / rowPerPage;
if(totalRow % rowPerPage != 0) {
lastPage = lastPage + 1; // ํ์ด์ง๊ฐ ๋ฑ ๋๋์ด๋จ์ด์ง์ง ์์ผ๋ฉด ํํ์ด์ง๊ฐ ๋ ํ์ํ๋ค
}
System.out.println("๋ง์ง๋ง ํ์ด์ง ๋๋ฒ: " + lastPage + "ํ์ด์ง");
// ๋์ด ๊ณ์ฐํ๊ธฐ
Calendar today = Calendar.getInstance(); // ์ค๋ ๋ ์ง ๊ตฌํ๊ธฐ
// ์ค๋ ๋ ์ง์ ๋
๋,์,์ผ ๋ณ์์ ๋ฐ๊ธฐ
int todayYear = today.get(Calendar.YEAR);
int todayMonth = today.get(Calendar.MONTH) + 1; // ์๋ฐapi์ ๋ง๋ฆฌ์db์ ์ ์์์ผ์ด ๋ค๋ฅด๋ฏ๋ก +1 ํด์ค๋ค (์๋ฐ๋ 0์๋ถํฐ ์์)
int todayDate = today.get(Calendar.DATE);
System.out.println("todayYear: " + todayYear + "๋
");
System.out.println("todayMonth: " + todayMonth + "์");
System.out.println("todayDate: " + todayDate + "์ผ");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>empList2.jsp</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<style>
.small {width: 30px; height: 30px;}
</style>
</head>
<body>
<div class="p-5 bg-primary text-white text-center">
<h1>Employees List</h1>
</div>
<div class="container mt-3">
<table class="table text-center">
<thead class="table-primary">
<tr><!-- ์ปฌ๋ผ๋ช
-->
<th>
no
<div>
<a href="./empList2.jsp?col=emp_no&ascDesc=ASC">🔼</a>
<a href="./empList2.jsp?col=emp_no&ascDesc=DESC">🔽</a>
</div>
</th>
<th>
age
<div>
<a href="./empList2.jsp?col=birth_date&ascDesc=ASC">🔼</a>
<a href="./empList2.jsp?col=birth_date&ascDesc=DESC">🔽</a>
</div>
</th>
<th>
first name
<div>
<a href="./empList2.jsp?col=first_name&ascDesc=ASC">🔼</a>
<a href="./empList2.jsp?col=first_name&ascDesc=DESC">🔽</a>
</div>
</th>
<th>
last name
<div>
<a href="./empList2.jsp?col=last_name&ascDesc=ASC">🔼</a>
<a href="./empList2.jsp?col=last_name&ascDesc=DESC">🔽</a>
</div>
</th>
<th>
gender
<div>
<a href="./empList2.jsp?col=gender&ascDesc=ASC">🔼</a>
<a href="./empList2.jsp?col=gender&ascDesc=DESC">🔽</a>
</div>
</th>
<th>
hire date
<div>
<a href="./empList2.jsp?col=hire_date&ascDesc=ASC">🔼</a>
<a href="./empList2.jsp?col=hire_date&ascDesc=DESC">🔽</a>
</div>
</th>
</tr>
</thead>
<tbody>
<%
for(Emp e : empList) {
%>
<tr>
<td><%=e.empNo%>๋ฒ</td>
<%
// e.birthDate์์ ๋
๋,์,์ผ intํ์
์ผ๋ก ๊ฐ์ ธ์ค๊ธฐ
int birthYear = Integer.parseInt(e.birthDate.substring(0,4));
int birthMonth = Integer.parseInt(e.birthDate.substring(5,7));
int birthDate = Integer.parseInt(e.birthDate.substring(8));
int age = todayYear - birthYear; // ๋์ด = ์ค๋๋
๋ - ํ์ด๋๋
๋
if(birthMonth <= todayMonth && birthDate <= todayDate) {
// ํ์ฌ ์์ด ํ์ด๋ ์๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๊ณ (์ด๋ฏธ ์ง๋ฌ๊ฑฐ๋ ์ด๋ฒ๋ฌ์ด๊ณ )
// ํ์ฌ ์ผ์ด ํ์ด๋ ์ผ๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ผ๋ฉด(์ด๋ฏธ ์ง๋ฌ๊ฑฐ๋ ์ค๋์ด๋ฉด)
// ์์ผ์ด ์ง๋ฌ๊ฑฐ๋ ์ค๋์ด ์์ผ์ด๋ฏ๋ก +1์ด ํด์ค๋ค
age = age + 1;
}
%>
<td><%=age%>์ธ</td>
<td><%=e.firstName%></td>
<td><%=e.lastName%></td>
<td>
<%
if(e.gender.equals("M")) { // Stringํ์
์ด๋ฏ๋ก equals ์ฌ์ฉ
%>
<img src="./img/m.JPG" class="small">
<%
} else {
%>
<img src="./img/f.JPG" class="small">
<%
}
%>
</td>
<td><%=e.hireDate%></td>
</tr>
<%
}
%>
</tbody>
</table>
</div>
<div class="mt-5 p-4 bg-secondary text-white text-center">
<%
if(curPage > 1) { // ์ฒซ๋ฒ์งธ ํ์ด์ง(1)๋ณด๋ค ํฐ ํ์ด์ง๋ถํฐ "์ด์ "์ ์ถ๋ ฅ
%>
<a href="./empList2.jsp?curPage=<%=curPage - 1%>&col=<%=col%>&ascDesc=<%=ascDesc%>" class="btn btn-primary btn-sm"> ์ด์ </a>
<%
}
%>
<%=curPage%>ํ์ด์ง <!-- ํ์ฌํ์ด์ง ์ถ๋ ฅ -->
<%
if(curPage < lastPage) { // ๋ง์ง๋ง ํ์ด์ง ๋๋ฒ๋ณด๋ค ์์ ํ์ด์ง๊น์ง๋ง "๋ค์"์ ์ถ๋ ฅ
%>
<a href="./empList2.jsp?curPage=<%=curPage + 1%>&col=<%=col%>&ascDesc=<%=ascDesc%>" class="btn btn-primary btn-sm"> ๋ค์ </a>
<%
}
%>
</div>
</body>
</html>
๐ ๊ฒฐ๊ณผ
ํด๋น ์ปฌ๋ผ์ ํ์ดํ๋ฅผ ๋๋ฅด๋ฉด, ํด๋น ์ปฌ๋ผ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์๊ณผ ๋ด๋ฆผ์ฐจ์์ผ๋ก ๋ฐ๋๊ฒ๋๋ค.
์ด๋ฒ์๋ select๋ฌธ์ where์ ์ ์ด์ฉํ์ฌ ์ฑ๋ณ ๊ฒ์๊ธฐ๋ฅ์ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์ ๋ค. if๋ฌธ์ ์ด์ฉํ์ฌ ์กฐ๊ฑด์ ๋ฐ๋ผ ์ฟผ๋ฆฌ๊ฐ ๋ฐ๋๊ฒ ๋๋ ๊ฒ์ ๋์ ์ฟผ๋ฆฌ๋ผ๊ณ ๋ถ๋ฅธ๋ค. ๋์ ์ฟผ๋ฆฌ๋ฅผ ์ด์ฉํ๋ฉด ๋ค์ํ ๊ฒ์์กฐ๊ฑด์ ๋ฐ๋ผ ๋ค๋ฅธ view๋ฅผ ์ฌ์ฉ์์๊ฒ ๋ณด์ฌ์ค ์ ์๋ค!
๐ ์์ฑ
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "vo.*" %>
<%
// ์ฑ๋ณ ๊ฒ์ ๊ธฐ๋ฅ ์ถ๊ฐ
// ํ์ฌํ์ด์ง ์์ฒญ๊ฐ ๊ฒ์ฌ
int curPage = 1; // ํ์ฌํ์ด์ง๋ 1๋ถํฐ ์์
if(request.getParameter("curPage") != null) { // ๋์ด์จ curPage๊ฐ null์ด๊ฑฐ๋ ๊ณต๋ฐฑ์ด ์๋ ๊ฒฝ์ฐ // ์ฆ, ์ด์ ๋๋ ๋ค์์ ๋๋ ์ ๊ฒฝ์ฐ
curPage = Integer.parseInt(request.getParameter("curPage")); // intํ์
์ผ๋ก ๊ฐ ๋ฐ๊ธฐ
}
System.out.println("ํ์ฌํ์ด์ง: " + curPage + "ํ์ด์ง");
// ํ์ด์ง๋น ์ถ๋ ฅํ ํ์ด ๋ช๊ฐ์ธ์ง
int rowPerPage = 10;
// ํ์ด์ง๋น ์์ ํ ๋ฒํธ๊ฐ ๋ช๋ฒ์ธ์ง
int startRow = (curPage - 1) * rowPerPage;
System.out.println("ํ์ฌ ์์ ํ๋ฒํธ: " + startRow + "๋ฒ");
/*
curPage startRow rowPerPage
1 0 30
2 30 30
3 60 30
4 90 30
*/
// ์์ฒญ๊ฐ ๊ฒ์ฌ
String gender = "";
if(request.getParameter("gender") != null) {
gender = request.getParameter("gender");
}
// ๋๋ผ์ด๋ฒ ๋ก๋ฉ // mariadb ์๋ฒ ์ ์
Class.forName("org.mariadb.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mariadb://127.0.0.1:3306/employees","****","****");
// ์ฟผ๋ฆฌ ๋จผ์ ์์ฑ // ์ฌ๊ธฐ ์์ ๋ค ๋ค์ด๊ฐ ๋ค์ ์ ๋ณด๊ธฐ (๋์ ์ฟผ๋ฆฌ)
String sql = null;
PreparedStatement stmt = null;
if(gender.equals("")) {
sql = "SELECT emp_no empNo, birth_date birthDate, first_name firstName, last_name lastName, gender gender, hire_date hireDate FROM employees LIMIT ?, ?";
stmt = conn.prepareStatement(sql); // ? 2๊ฐ
stmt.setInt(1, startRow);
stmt.setInt(2, rowPerPage);
} else { // where์ ์ถ๊ฐ
sql = "SELECT emp_no empNo, birth_date birthDate, first_name firstName, last_name lastName, gender gender, hire_date hireDate FROM employees WHERE gender=? LIMIT ?, ?";
stmt = conn.prepareStatement(sql); // ? 3๊ฐ
stmt.setString(1, gender);
stmt.setInt(2, startRow);
stmt.setInt(3, rowPerPage);
}
System.out.println("empList sql: " + stmt);
ResultSet rs = stmt.executeQuery();
// ResultSet -> ArrayList<Emp>
ArrayList<Emp> empList = new ArrayList<Emp>();
while(rs.next()) {
Emp e = new Emp();
e.empNo = rs.getInt("empNo");
e.birthDate = rs.getString("birthDate");
e.firstName = rs.getString("firstName");
e.lastName = rs.getString("lastName");
e.gender = rs.getString("gender");
e.hireDate = rs.getString("hireDate");
empList.add(e);
}
// ๋ฐ์ดํฐ๊ฐ ์ด ๋ชํ์ธ์ง ๊ตฌํ๊ธฐ count(*) ์ฌ์ฉ
String sql2 = "SELECT count(*) FROM employees";
PreparedStatement stmt2 = conn.prepareStatement(sql2);
ResultSet rs2 = stmt2.executeQuery();
System.out.println("empList sql2: " + stmt2);
// ResultSet -> int totalRow์ ๊ฐ์ ๋ฃ๋๋ค
int totalRow = 0;
if(rs2.next()) {
totalRow = rs2.getInt("count(*)");
}
System.out.println("์ ์ฒด ๋ฐ์ดํฐ ํ์ ์: ์ด " + totalRow + "๊ฐ");
// ์ด ์ถ๋ ฅ๋๋ ํ์ด์ง์ ์(๋ง์ง๋ง ํ์ด์ง ๋๋ฒ) ๊ตฌํ๊ธฐ
int lastPage = totalRow / rowPerPage;
if(totalRow % rowPerPage != 0) {
lastPage = lastPage + 1; // ํ์ด์ง๊ฐ ๋ฑ ๋๋์ด๋จ์ด์ง์ง ์์ผ๋ฉด ํํ์ด์ง๊ฐ ๋ ํ์ํ๋ค
}
System.out.println("๋ง์ง๋ง ํ์ด์ง ๋๋ฒ: " + lastPage + "ํ์ด์ง");
// ๋์ด ๊ณ์ฐํ๊ธฐ
Calendar today = Calendar.getInstance(); // ์ค๋ ๋ ์ง ๊ตฌํ๊ธฐ
// ์ค๋ ๋ ์ง์ ๋
๋,์,์ผ ๋ณ์์ ๋ฐ๊ธฐ
int todayYear = today.get(Calendar.YEAR);
int todayMonth = today.get(Calendar.MONTH) + 1; // ์๋ฐapi์ ๋ง๋ฆฌ์db์ ์ ์์์ผ์ด ๋ค๋ฅด๋ฏ๋ก +1 ํด์ค๋ค (์๋ฐ๋ 0์๋ถํฐ ์์)
int todayDate = today.get(Calendar.DATE);
System.out.println("todayYear: " + todayYear + "๋
");
System.out.println("todayMonth: " + todayMonth + "์");
System.out.println("todayDate: " + todayDate + "์ผ");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>empList.jsp</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<style>
.small {width: 30px; height: 30px;}
</style>
</head>
<body>
<div class="p-5 bg-primary text-white text-center">
<h1>Employees List</h1>
</div>
<div class="container mt-3">
<table class="table text-center">
<thead class="table-primary">
<tr><!-- ์ปฌ๋ผ๋ช
-->
<th>no</th>
<th>age</th>
<th>first name</th>
<th>last name</th>
<th>gender</th>
<th>hire date</th>
</tr>
</thead>
<tbody>
<%
for(Emp e : empList) {
%>
<tr>
<td><%=e.empNo%>๋ฒ</td>
<%
// e.birthDate์์ ๋
๋,์,์ผ intํ์
์ผ๋ก ๊ฐ์ ธ์ค๊ธฐ
int birthYear = Integer.parseInt(e.birthDate.substring(0,4));
int birthMonth = Integer.parseInt(e.birthDate.substring(5,7));
int birthDate = Integer.parseInt(e.birthDate.substring(8));
int age = todayYear - birthYear; // ๋์ด = ์ค๋๋
๋ - ํ์ด๋๋
๋
if(birthMonth <= todayMonth && birthDate <= todayDate) {
// ํ์ฌ ์์ด ํ์ด๋ ์๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๊ณ (์ด๋ฏธ ์ง๋ฌ๊ฑฐ๋ ์ด๋ฒ๋ฌ์ด๊ณ )
// ํ์ฌ ์ผ์ด ํ์ด๋ ์ผ๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ผ๋ฉด(์ด๋ฏธ ์ง๋ฌ๊ฑฐ๋ ์ค๋์ด๋ฉด)
// ์์ผ์ด ์ง๋ฌ๊ฑฐ๋ ์ค๋์ด ์์ผ์ด๋ฏ๋ก +1์ด ํด์ค๋ค
age = age + 1;
}
%>
<td><%=age%>์ธ</td>
<td><%=e.firstName%></td>
<td><%=e.lastName%></td>
<td>
<%
if(e.gender.equals("M")) { // Stringํ์
์ด๋ฏ๋ก equals ์ฌ์ฉ
%>
<img src="./img/m.JPG" class="small">
<%
} else {
%>
<img src="./img/f.JPG" class="small">
<%
}
%>
</td>
<td><%=e.hireDate%></td>
</tr>
<%
}
%>
</tbody>
</table>
<div class="text-center">
<!-- ์ฑ๋ณ ๊ฒ์ ๊ธฐ๋ฅ ์ถ๊ฐ -->
<form action="./empList.jsp" method="get">
<select name="gender">
<option value="">==์ฑ๋ณ์ ํ==</option>
<option value="M">==๋จ==</option>
<option value="F">==์ฌ==</option>
</select>
<button type="submit">์ฑ๋ณ๊ฒ์</button>
</form>
</div>
</div>
<!-- ํ์ด์ง -->
<div class="mt-5 p-4 bg-secondary text-white text-center">
<%
if(curPage > 1) { // ์ฒซ๋ฒ์งธ ํ์ด์ง(1)๋ณด๋ค ํฐ ํ์ด์ง๋ถํฐ "์ด์ "์ ์ถ๋ ฅ
%>
<a href="./empList.jsp?curPage=<%=curPage - 1%>&gender=<%=gender%>" class="btn btn-primary btn-sm"> ์ด์ </a>
<%
}
%>
<%=curPage%>ํ์ด์ง <!-- ํ์ฌํ์ด์ง ์ถ๋ ฅ -->
<%
if(curPage < lastPage) { // ๋ง์ง๋ง ํ์ด์ง ๋๋ฒ๋ณด๋ค ์์ ํ์ด์ง๊น์ง๋ง "๋ค์"์ ์ถ๋ ฅ
%>
<a href="./empList.jsp?curPage=<%=curPage + 1%>&gender=<%=gender%>" class="btn btn-primary btn-sm"> ๋ค์ </a>
<%
}
%>
</div>
</body>
</html>
๐ ์ถ๋ ฅ