ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฐ˜์‘ํ˜•

ํŒ”๋กœ์›Œ, ํŒ”๋กœ์ž‰ ๋ฆฌ์ŠคํŠธ๋ฅผ ์กฐํšŒํ•˜๋Š” ๊ฒƒ์€ ๊ฐœ์ธ ํŽ˜์ด์ง€๋ฅผ ์กฐํšŒํ•  ๋•Œ ๋ณด์—ฌ์ค˜์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— PostsController์—์„œ ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค.

 

 

Controller


PostsController

@Autowired
private IFollowService followService;

IFollowService ์ž๋™์ฃผ์ž…

//personal-list ์š”์ฒญ : ๊ฐœ์ธ ๊ฒŒ์‹œ๋ฌผ ๋ณด์ด๋Š” ํŽ˜์ด์ง€
@RequestMapping(value="/{id}", method=RequestMethod.GET)
public String personalList(@PathVariable String id, Model model, HttpSession session) throws Exception {
	
	
	//๊ฐœ์ธ ํŽ˜์ด์ง€ ์ฃผ์ธ ์ •๋ณด ๋‹ด๊ธฐ
	UsersVO user = usersService.inquiryOfUserById(id);
	//๋กœ๊ทธ์ธํ•œ ํšŒ์› (=๋‚˜) ์ •๋ณด ๋‹ด๊ธฐ
	Object object = session.getAttribute("login");
	UsersVO loginUser = (UsersVO)object;
	
	
	//๊ฐœ์ธํŽ˜์ด์ง€์˜ ์œ ์ € ๋ฒˆํ˜ธ ๊ฐ€์ ธ์˜ค๊ธฐ
	int userNo = user.getUserNo();
	//๋กœ๊ทธ์ธ ํšŒ์› ์œ ์ € ๋ฒˆํ˜ธ ๊ฐ€์ ธ์˜ค๊ธฐ
	int loginUserNo = loginUser.getUserNo();
	logger.info("ํ˜„์žฌ ํŽ˜์ด์ง€ ์ฃผ์ธ์˜ ๋ฒˆํ˜ธ : " + userNo + ", ๋กœ๊ทธ์ธ ์œ ์ €์˜ ๋ฒˆํ˜ธ : " + loginUserNo);
	
	
	//ํŒ”๋กœ์šฐ ๊ฐ์ฒด ์ƒ์„ฑ
	FollowVO follow = new FollowVO();
	follow.setActiveUser(loginUserNo); 	//ํ•˜๋Š”๋†ˆ
	follow.setPassiveUser(userNo);		//๋‹นํ•˜๋Š”๋†ˆ
	
	//ํŒ”๋กœ์šฐ ์œ ๋ฌด ์ฒดํฌ
	int followCheck = followService.isFollow(follow);
	logger.info("ํŒ”๋กœ์šฐ ์œ ๋ฌด ์ฒดํฌ : " + followCheck);

	//ํŒ”๋กœ์›Œ ๋ฆฌ์ŠคํŠธ -> (๊ฐœ์ธํŽ˜์ด์ง€์—์„œ)๋‚˜๋ฅผ ํŒ”๋กœ์šฐํ•˜๋Š” ๋†ˆ๋“ค ๋ชฉ๋ก
	List<FollowVO> followerList = followService.selectPassiveUserList(userNo);
	//ํŒ”๋กœ์ž‰๋ฆฌ์ŠคํŠธ -> (๊ฐœ์ธํŽ˜์ด์ง€์—์„œ) ๋‚ด๊ฐ€ ํŒ”๋กœ์šฐ ํ•˜๋Š” ๋†ˆ๋“ค ๋ชฉ๋ก
	List<FollowVO> followingList = followService.selectActiveUserList(userNo);
	
	//์‚ฌ์šฉ์ž ์•„์ด๋””๋กœ ์‚ฌ์šฉ์ž ๋ฒˆํ˜ธ(pk)๋ฅผ ์กฐํšŒํ•ด์„œ ๊ทธ ๋ฒˆํ˜ธ๋กœ ๊ฒŒ์‹œ๋ฌผ ๊ฐ€์ ธ์˜ค๊ธฐ
	model.addAttribute("post", postsService.selectPostListById(id));
	//์‚ฌ์šฉ์ž ์•„์ด๋””๋กœ ํšŒ์›์˜ ๋ชจ๋“  ์ •๋ณด ์กฐํšŒํ•˜๊ธฐ
	model.addAttribute("user", user);
	//ํŒ”๋กœ์šฐ ์ฒดํฌ ์œ ๋ฌด
	model.addAttribute("followCheck", followCheck);
	//ํŒ”๋กœ์›Œ ๋ฆฌ์ŠคํŠธ
	model.addAttribute("followerList", followerList);
	//ํŒ”๋กœ์ž‰ ๋ฆฌ์ŠคํŠธ
	model.addAttribute("followingList", followingList);
	
	
	return "post/personal-list";
}
//๊ฒŒ์‹œ๊ธ€ ์ž‘์„ฑ ํŽ˜์ด์ง€ personal-write.jsp ์š”์ฒญ
@RequestMapping(value="/{id}/personal-write", method=RequestMethod.GET)
public String personalWrite(@PathVariable String id, Model model, HttpSession session) throws Exception {

	//id๋กœ ํšŒ์›์˜ ๋ชจ๋“  ์ •๋ณด ์กฐํšŒ
	UsersVO user = usersService.inquiryOfUserById(id);
	
	//๋กœ๊ทธ์ธํ•œ ํšŒ์› (=๋‚˜) ์ •๋ณด ๋‹ด๊ธฐ
	Object object = session.getAttribute("login");
	UsersVO loginUser = (UsersVO)object;
	
	//๊ฐœ์ธํŽ˜์ด์ง€์˜ ์œ ์ € ๋ฒˆํ˜ธ ๊ฐ€์ ธ์˜ค๊ธฐ
	int userNo = user.getUserNo();
	//๋กœ๊ทธ์ธ ํšŒ์› ์œ ์ € ๋ฒˆํ˜ธ ๊ฐ€์ ธ์˜ค๊ธฐ
	int loginUserNo = loginUser.getUserNo();
	logger.info("ํ˜„์žฌ ํŽ˜์ด์ง€ ์ฃผ์ธ์˜ ๋ฒˆํ˜ธ : " + userNo + ", ๋กœ๊ทธ์ธ ์œ ์ €์˜ ๋ฒˆํ˜ธ : " + loginUserNo);
	
	//ํŒ”๋กœ์šฐ ๊ฐ์ฒด ์ƒ์„ฑ
	FollowVO follow = new FollowVO();
	follow.setActiveUser(loginUserNo); 	//ํ•˜๋Š”๋†ˆ
	follow.setPassiveUser(userNo);		//๋‹นํ•˜๋Š”๋†ˆ
	
	//ํŒ”๋กœ์šฐ ์œ ๋ฌด ์ฒดํฌ
	int followCheck = followService.isFollow(follow);
	logger.info("ํŒ”๋กœ์šฐ ์œ ๋ฌด ์ฒดํฌ : " + followCheck);
	
	//ํŒ”๋กœ์›Œ ๋ฆฌ์ŠคํŠธ -> (๊ฐœ์ธํŽ˜์ด์ง€์—์„œ)๋‚˜๋ฅผ ํŒ”๋กœ์šฐํ•˜๋Š” ๋†ˆ๋“ค ๋ชฉ๋ก
	List<FollowVO> followerList = followService.selectPassiveUserList(userNo);
	//ํŒ”๋กœ์ž‰๋ฆฌ์ŠคํŠธ -> (๊ฐœ์ธํŽ˜์ด์ง€์—์„œ) ๋‚ด๊ฐ€ ํŒ”๋กœ์šฐ ํ•˜๋Š” ๋†ˆ๋“ค ๋ชฉ๋ก
	List<FollowVO> followingList = followService.selectActiveUserList(userNo);
	
	//์‚ฌ์šฉ์ž ์•„์ด๋””๋กœ ์‚ฌ์šฉ์ž ๋ฒˆํ˜ธ(pk)๋ฅผ ์กฐํšŒํ•ด์„œ ๊ทธ ๋ฒˆํ˜ธ๋กœ ๊ฒŒ์‹œ๋ฌผ ๊ฐ€์ ธ์˜ค๊ธฐ
	model.addAttribute("post", postsService.selectPostListById(id));
	//ํšŒ์›์˜ ์ •๋ณด
	model.addAttribute("user", user);
	//ํŒ”๋กœ์šฐ ์ฒดํฌ ์œ ๋ฌด
	model.addAttribute("followCheck", followCheck);
	//ํŒ”๋กœ์›Œ ๋ฆฌ์ŠคํŠธ
	model.addAttribute("followerList", followerList);
	//ํŒ”๋กœ์ž‰ ๋ฆฌ์ŠคํŠธ
	model.addAttribute("followingList", followingList);	
	
	return "post/personal-write";
}

personal-list์™€ personal-write ๋‘ ํŽ˜์ด์ง€์—์„œ ์‚ฌ์šฉ๋˜๋ฏ€๋กœ ์ˆ˜์ •ํ•ด์ค€๋‹ค.

 

 

 

 

 

 

Service


FollowService

@Override
public int isFollow(FollowVO follow) {
	return followDAO.isFollow(follow);
}

@Override
public List<FollowVO> selectActiveUserList(int activeUser) {
	return followDAO.selectActiveUserList(activeUser);
}

@Override
public List<FollowVO> selectPassiveUserList(int passiveUser) {
	return followDAO.selectPassiveUserList(passiveUser);
}
  • ํŒ”๋กœ์šฐ ์ฒดํฌ ์œ ๋ฌด
  • ํŒ”๋กœ์ž‰ ๋ฆฌ์ŠคํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ
  • ํŒ”๋กœ์›Œ ๋ฆฌ์ŠคํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ

 

 

 

 

 

 

View


personal-static

<c:if test="${followingList.size() <= 0 }">
	<p>ํŒ”๋กœ์ž‰ํ•œ ํšŒ์›์ด ์—†์Šต๋‹ˆ๋‹ค.</p>
</c:if>
<c:if test="${followingList.size() > 0 }">
	<c:forEach var="list" items="${followingList }">
		<li class="follow-li">
			<div class="profile-section">
				<c:set var="len" value="${fn:length(list.profileName) }" />
				<c:set var="filetype" value="${fn:toUpperCase(fn:substring(list.profileName, len-4, len)) }" />
				<c:choose>
					<c:when test="${(filetype eq '.JPG') or (filetype eq 'JPEG') or (filetype eq '.GIF') or (filetype eq '.PNG')}">
						<img class="profile-photo" src="<c:url value='/user/profile/${list.passiveUser }'/>">
					</c:when>
					<c:otherwise>
						<img class="profile-photo" src="<c:url value='/img/none-user-img.jpg'/>">
					</c:otherwise>
				</c:choose>
				<p class="profile-id"><a href="<c:url value='/post/${list.passiveUserId }' />">${list.passiveUserId }</a></p>
				<!-- <button class="following-list-btn">ํŒ”๋กœ์ž‰</button> -->
			</div>
		</li>
	</c:forEach>
</c:if>

๋ฆฌ์ŠคํŠธ ๋ชฉ๋ก์€ ๋ชจ๋‹ฌ๋กœ ์ƒ์„ฑ. ํŒ”๋กœ์ž‰๊ณผ ํŒ”๋กœ์›Œ ๊ฐ™๊ฒŒ ๋งŒ๋“ค์–ด์ฃผ์—ˆ๋‹ค.

๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€