: View와 Controller를 JSP로, Model을 Java로 구현
→ 구현이 쉽지만 유지보수가 어려움
>> 로그인+회원가입 페이지 만들기
>> 게시판 페이지 만들기
calendar.jsp
<%
Calendar cal = Calendar.getInstance();
// 달력 생성을 위해 1일로 설정
cal.set(year, month-1, 1); // 달 인자: 0~11
// 설정일의 요일
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
// 해당 달의 마지막날
int lastday = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
%>
calendar.jsp
<!-- 달력 내 날짜칸 -->
<%
for(int i = 1; i <= lastday; i++) {
%>
<td>
<span class="callist"> <!-- 날짜 -->
<a href='callist.jsp?year=<%=year%>&month=<%=month%>&day=<%=i%>'>
<%= i %>
</a>
</span>
<span class="calwrite"> <!-- 일정생성 버튼 -->
<a href='calwrite.jsp?year=<%=year%>&month=<%=month%>&day=<%=i%>'>
+
</a>
</span>
<div class="daytable"> <!-- 일정 테이블 -->
<%= CalendarUtil.makeTable(year, month, i, list) %>
</div>
</td>
<%
// 줄바꿈
if((i + dayOfWeek - 1) % 7 == 0) {
%>
</tr><tr>
<%
}
}
%>
CalendarUtil.java
// 캘린더 내 날짜별 일정 테이블
public static String makeTable(int year, int month,
int day, List<CalendarDto> list) {
String str = "<table>";
// 날짜형식 변경 20230228
String date = year + twoDigit(month + "") + twoDigit(day + "");
for (CalendarDto dto: list) {
if (date.equals(dto.getRdate().substring(0, 8))) {
str += "<tr><td>";
str += "<a href='caldetail.jsp?seq=" + dto.getSeq() + "'>";
str += truncate(dto.getTitle());
str += "</a></td></tr>";
}
}
str += "</table>";
return str;
calwrite.jsp
<tr>
<th>일시</th>
<td>
<input type="date" name="date" id="date">
<input type="time" name="time" id="time">
</td>
</tr>
.
.
.
<script type="text/javascript">
let year = "<%= year %>";
let month = "<%= month %>";
let day = "<%= day %>";
let date = new Date();
document.getElementById("date").value = year + "-" + month + "-" + day;
document.getElementById("time").value = date.getHours() + ":" + date.getMinutes();
</script>
create table calendar(
seq int auto_increment primary key,
id varchar(50) not null,
title varchar(200) not null,
content varchar(4000),
rdate varchar(12) not null,
wdate timestamp not null
);
alter table calendar
add
constraint fk_cal_id foreign key(id)
references member(id);
getCalList()
// 해당 달의 모든 일정 리스트
public List<CalendarDto> getCalList(String id, String yyyymm) {
String sql = " select seq, id, title, content, rdate, wdate "
+ " from (select row_number()over( "
+ " partition by substr(rdate, 1, 8) order by rdate) "
+ " as rnum, seq, id, title, content, rdate, wdate "
+ " from calendar "
+ " where id=? and substr(rdate, 1, 6)=?) a "
+ " where rnum between 1 and 5 ";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<CalendarDto> list = new ArrayList<CalendarDto>();
try {
conn = DBConnection.getConnection();
System.out.println("1/3 getCalendarList success");
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
pstmt.setString(2, yyyymm);
System.out.println("2/3 getCalendarList success");
rs = pstmt.executeQuery();
System.out.println("3/3 getCalendarList success");
while(rs.next()) {
int i = 1;
list.add(new CalendarDto(rs.getInt(i++),
rs.getString(i++),
rs.getString(i++),
rs.getString(i++),
rs.getString(i++),
rs.getString(i++)));
}
} catch (SQLException e) {
System.out.println("getCalendarList fail");
e.printStackTrace();
} finally {
DBClose.close(conn, pstmt, rs);
}
return list;
}