Posts DEVIL: DispatcherServlet에 따른 비활성 상태의 데이터 추출 여부 변경
Post
Cancel

DEVIL: DispatcherServlet에 따른 비활성 상태의 데이터 추출 여부 변경

문제

app DispatcherServlet과 admin DispatcherServlet 모두 같은 Mapper 파일을 참조하고 있다. 그리고 Mapper에서는 활성여부를 판단하지 않고 모든 데이터를 select하고 있다. 그러나 app DispatcherServlet의 경우 DB에서 데이터를 가져올 때부터 비활성상태의 게시글, 태그, 유저, 댓글은 가져오지 말아야 한다. 이를 위해서는 list(), detail()와 같이 데이터를 가져오는 메서드에서 Map 객체를 파라미터로 넘겨주도록 바꿔야 한다. 그리고 Map 에는 type이라는 이름으로 admin인지 app인지를 PageController에서 지정하여 메서드를 호출하도록 만든다.

해결방법

  • UserService의 listFollower(), listFollowing(), detail() 파라미터를 Map 객체로 바꿨다.
  • UserDao의 findFollower(), findByFolloer(), findByNo() 파라미터를 Map 객체로 바꿨다.
  • User Mapper를 다음과 같이 변경했다.

findByNo

1
2
3
4
5
6
7
<select id="findByNo" resultMap="UserMap" parameterType="map">
<include refid="sql1" />
where u.uno=#{userNo}
<if test="type == 'app'">
		 and u.state = 1
</if>
</select>

findByFollower

1
2
3
4
5
6
7
8
9
10
<select id="findByFollower" resultMap="UserMap"
parameterType="map">
  <include refid="sql2" />
  inner join follow f on f.fwing_no = u.uno
where f.fwer_no=#{user.no}
<if test="type == 'app'">
     and u.state = 1
  </if>
order by f.cdt desc
</select>

findFollower

1
2
3
4
5
6
7
8
9
10
<select id="findFollower" resultMap="UserMap"
  parameterType="map">
  <include refid="sql2" />
  inner join follow f on f.fwer_no = u.uno
  where f.fwing_no=#{user.no}
  <if test="type == 'app'">
     and u.state = 1
  </if>
  order by f.cdt desc
</select>

findAll 및 select를 하는 다른 메서드의 경우 admin과 app이 공유하지 않기 때문에 그대로 두었다.

변경된 유저 서비스의 메서드를 사용하는 Controller들에서(UserController, ArticleController, CommentController, FollowController) Map 객체를 만들어 호출 시 파라미터로 넘겨주도록 변경하였다

This post is licensed under CC BY 4.0 by the author.

DEVIL: 개인 피드 구현: 게시글 중복 문제

DEVIL: 알림 기능 구현

Loading comments from Disqus ...