Skip to content

Commit 8489fc9

Browse files
committed
Lesson 07 - step 05
1 parent 3c36fee commit 8489fc9

71 files changed

Lines changed: 1813 additions & 11 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Lesson07/build/classes/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/spms
2+
/log4j.properties
979 Bytes
Binary file not shown.

Lesson07/src/log4j.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Global logging configuration
2+
log4j.rootLogger=ERROR, stdout
3+
4+
# MyBatis logging configuration...
5+
log4j.logger.spms.dao=DEBUG
6+
7+
# Console output...
8+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
9+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
10+
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

Lesson07/src/spms/dao/MySqlProjectDao.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
//3. 동적 SQL 적용
44
import java.util.HashMap;
5+
import java.util.Hashtable;
56
import java.util.List;
67

78
import org.apache.ibatis.session.SqlSession;
@@ -51,9 +52,37 @@ public Project selectOne(int no) throws Exception {
5152
public int update(Project project) throws Exception {
5253
SqlSession sqlSession = sqlSessionFactory.openSession();
5354
try {
54-
int count = sqlSession.update("spms.dao.ProjectDao.update", project);
55-
sqlSession.commit();
56-
return count;
55+
Project original = sqlSession.selectOne(
56+
"spms.dao.ProjectDao.selectOne", project.getNo());
57+
58+
Hashtable<String,Object> paramMap = new Hashtable<String,Object>();
59+
if (!project.getTitle().equals(original.getTitle())) {
60+
paramMap.put("title", project.getTitle());
61+
}
62+
if (!project.getContent().equals(original.getContent())) {
63+
paramMap.put("content", project.getContent());
64+
}
65+
if (project.getStartDate().compareTo(original.getStartDate()) != 0) {
66+
paramMap.put("startDate", project.getStartDate());
67+
}
68+
if (project.getEndDate().compareTo(original.getEndDate()) != 0) {
69+
paramMap.put("endDate", project.getEndDate());
70+
}
71+
if (project.getState() != original.getState()) {
72+
paramMap.put("state", project.getState());
73+
}
74+
if (!project.getTags().equals(original.getTags())) {
75+
paramMap.put("tags", project.getTags());
76+
}
77+
78+
if (paramMap.size() > 0) {
79+
paramMap.put("no", project.getNo());
80+
int count = sqlSession.update("spms.dao.ProjectDao.update", paramMap);
81+
sqlSession.commit();
82+
return count;
83+
} else {
84+
return 0;
85+
}
5786
} finally {
5887
sqlSession.close();
5988
}

Lesson07/src/spms/dao/MySqlProjectDao.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@
4444
where PNO=#{value}
4545
</select>
4646

47-
<update id="update" parameterType="project">
48-
update PROJECTS set
49-
PNAME=#{title},
50-
CONTENT=#{content},
51-
STA_DATE=#{startDate},
52-
END_DATE=#{endDate},
53-
STATE=#{state},
54-
TAGS=#{tags}
47+
<update id="update" parameterType="map">
48+
update PROJECTS
49+
<set>
50+
<if test="title != null">PNAME=#{title},</if>
51+
<if test="content != null">CONTENT=#{content},</if>
52+
<if test="startDate != null">STA_DATE=#{startDate},</if>
53+
<if test="endDate != null">END_DATE=#{endDate},</if>
54+
<if test="state != null">STATE=#{state},</if>
55+
<if test="tags != null">TAGS=#{tags}</if>
56+
</set>
5557
where PNO=#{no}
5658
</update>
5759

Lesson07/src/spms/dao/mybatis-config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"http://mybatis.org/dtd/mybatis-3-config.dtd">
55
<configuration>
66
<properties resource="spms/dao/db.properties"/>
7+
8+
<settings>
9+
<setting name="logImpl" value="LOG4J"/>
10+
</settings>
711

812
<typeAliases>
913
<typeAlias type="spms.vo.Project" alias="project"/>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<%@ page
2+
language="java"
3+
contentType="text/html; charset=UTF-8"
4+
pageEncoding="UTF-8"%>
5+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
6+
"http://www.w3.org/TR/html4/loose.dtd">
7+
<html>
8+
<head>
9+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
10+
<title>시스템 오류!</title>
11+
</head>
12+
<body>
13+
<p>요청을 처리하는 중에 문제가 발생하였습니다. 잠시 후에 다시 요청하시기 바랍니다.
14+
만약 계속해서 이 문제가 발생된다면 시스템 운영팀(사내번호: 8282)에 연락하기 바랍니다.</p>
15+
</body>
16+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<%-- 3. 메뉴 추가 --%>
2+
<%@page import="spms.vo.Member"%>
3+
<%@ page language="java" contentType="text/html; charset=UTF-8"
4+
pageEncoding="UTF-8"%>
5+
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
6+
<div style="background-color:#00008b;color:#ffffff;height:20px;padding: 5px;">
7+
SPMS(Simple Project Management System)
8+
9+
<span style="float:right;">
10+
<a style="color:white;"
11+
href="<%=request.getContextPath()%>/project/list.do">프로젝트</a>
12+
<a style="color:white;"
13+
href="<%=request.getContextPath()%>/member/list.do">회원</a>
14+
15+
<c:if test="${empty sessionScope.member or
16+
empty sessionScope.member.email}">
17+
<a style="color:white;"
18+
href="<%=request.getContextPath()%>/auth/login.do">로그인</a>
19+
</c:if>
20+
21+
<c:if test="${!empty sessionScope.member and
22+
!empty sessionScope.member.email}">
23+
${sessionScope.member.name}
24+
(<a style="color:white;"
25+
href="<%=request.getContextPath()%>/auth/logout.do">로그아웃</a>)
26+
</c:if>
27+
</span>
28+
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Class-Path:
3+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
<div style="background-color:#f0fff0;height:20px;padding:5px; margin-top:10px">
4+
SPMS &copy; 2013
5+
</div>

0 commit comments

Comments
 (0)