1) ArticleRepository.xml
<select id="getArticles" resultType="Article">
SELECT A.* , M.nickname AS extra__writer
FROM article AS A
INNER JOIN `member` AS M
ON A.memberId = M.id
ORDER BY A.id DESC
</select>
2) list.jsp
<tbody>
<c:forEach var="article" items="${articles}">
<tr>
<td>${article.id } </td>
<td>${article.regDate.substring(0,10)}</td>
<td><a class="hover:underline" href="../article/detail?id=${article.id}">${article.title}</a></td>
<td>${article.extra__writer}</td>
</tr>
1) ArticleRepository.xml
<select id="getArticle" resultType="Article">
SELECT A.* , M.nickname AS extra__writer
FROM article AS A
INNER JOIN `member` AS M
ON A.memberId = M.id
WHERE id = #{id}
</select>
2) list.jsp
<tr>
<td>내용</td><td>${article.body }</td>
</tr>
<tr>
<td>작성자</td><td>${article.extra__writer }</td>
</tr>
1) detail.jsp
<div class= "btns">
<button class ="btn-text-link" type="button" onclick="history.back()">뒤로가기</button>
<a class ="btn-text-link" href="modify?id=${article.id }">수정</a>
<a class ="btn-text-link" onclick="if(confirm('삭제하시겠습니까?') == false) return false;" href="doDelete?id=${article.id }">삭제</a>
</div>
1) ArticleController (detail)
@RequestMapping("/usr/article/detail")
public String showDetail(HttpSession httpSession,Model model ,int id) {
int loginedMemberId= -1;
if(httpSession.getAttribute("loginedMemberId") !=null) {
loginedMemberId =(int)httpSession.getAttribute("loginedMemberId");
}
Article article = articleService.getForPrintArticle(loginedMemberId,id);
model.addAttribute("article", article);
return "usr/article/detail";
}
loginedMemberId
를 구하고 getForPrintArticle()의 인자로 넣어준다.2) ArticleService (getForPrintArticle)
public Article getForPrintArticle(int actorId, int id) {
Article article = articleRepository.getForPrintArticle(id);
updateForPrintData(actorId,article);
return article;
}
updateForPrintData(actorId,article)
는 가져온 게시물에 수정/삭제 권한 데이터
를 추가 하기위한 메소드3) ArticleService (updateForPrintData(actorId,article))
private void updateForPrintData(int actorId, Article article) {
if (article == null) {
return;
}
ResultData actorCanDeleteRd = actorCanDelete(actorId,article);
article.setExtra__actorCanDelete(actorCanDeleteRd.isSuccess());
}
isSuccess()
메소드는 boolean값으로 권한여부를 반환setExtra__actorCanDelete(actorCanDeleteRd.isSuccess())
: 게시물에 대한 권한 여부데이터를 추가4) Article
public class Article {
~~생략~~
private boolean extra__actorCanDelete;
5) detail.jsp
<div class= "btns">
<button class ="btn-text-link" type="button" onclick="history.back()">뒤로가기</button>
<a class ="btn-text-link" href="modify?id=${article.id }">수정</a>
<c:if test= "${article.extra__actorCanDelete}" >
<a class ="btn-text-link" onclick="if(confirm('삭제하시겠습니까?') == false) return false;" href="doDelete?id=${article.id }">삭제</a>
</c:if>
</div>