개발

스프링 시큐리티 : resultMap (authmap)

Domaya 2023. 1. 31. 18:57

member테이블엔 권한 관련 정보가 없다.

이러한 권한 정보는 memberauth 테이블에 존재한다.

 

 

mapper에서는 이 member를 member와 memberauth 테이블을 조인해서 가져오기 때문에

resultMap을 사용했다.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="kr.or.kosa.dao.MemberDao">
	<!-- JOIN 등으로 기존 VO와 구조가 다른 데이터가 리턴되는 경우 resultMap으로 묶는다.-->
	<resultMap type="kr.or.kosa.dto.Member" id="memberMap">
	   <result property="memberId" column="memberid"/>
	   <result property="password" column="password"/>
	   <result property="name" column="name"/>
	   <result property="major" column="major"/>
	   <result property="email" column="email"/>
	   <result property="gender" column="gender"/>
	   <result property="phone" column="phone"/>
	   <result property="parentsPhone" column="parentsPhone"/>
	   <result property="memberPoint" column="memberPoint"/>
	   <result property="demerit" column="demerit"/>
	   <collection property="authList" resultMap="authMap">
	   </collection> 
	 </resultMap>
	  
	 <resultMap type="kr.or.kosa.dto.MemberAuth" id="authMap">
	   <result property="memberId" column="memberid"/>
	   <result property="auth" column="auth"/>
	 </resultMap>
	
	<!-- getAllMember(전체조회) -->
	<select id="getAllMember" parameterType="string" resultMap="memberMap" resultType="kr.or.kosa.dto.Member">             
	  SELECT m.memberid, m.password, m.universitycode, m.name, m.major,
	  m.email, m.gender, m.phone, m.parentsphone, m.memberpoint, m.demerit, auth
	  FROM MEMBER m LEFT join MEMBERAUTH a ON m.MEMBERID = a.MEMBERID WHERE a.auth = 'ROLE_MEMBER'
	  AND m.UNIVERSITYCODE = #{universitycode}
	</select>
	 
</mapper>