728x90
resultType resultMap parameterType parameterMap
- resultType : 비즈니스 로직으로 반환할, 결과값의 자료형
- resultMap : 비즈니스 로직으로 반환할, 결과값을 담은 객체
- parameterType : 비즈니스 로직으로부터 전달 받은, SQL 구문에 사용될 매개변수의 자료형
- parameterMap : 비즈니스 로직으로부터 전달 받은, SQL 구문에 사용될 매개변수를 담은 객체
resultType
하나의 변수를 반환할 때
<!-- 문자열을 반환할 때 -->
<select id="testSelect" resultType="java.lang.String">
select name
from testTable
where 1=1
and use = 'Y'
and seq = 52
</select>
<!-- 숫자형을 반환할 때 -->
<select id="testSelect" resultType="java.lang.Integer">
select count(*)
from testTable
where 1=1
and use = 'Y'
</select>
<!-- 여러 컬럼을 반환할 때 -->
<select id="testSelect" resultType="java.util.HashMap">
select *
from testTable
where 1=1
and use = 'Y'
</select>
resultMap
정해진 형태를 갖춰 반환할 때
<!-- resultMap을 선언해줘야 한다. -->
<!-- resultMap을 구분할 수 있는 id와 경로(type)를 설정해줘야 한다. -->
<resultMap id="test_resultMap" type="test.project.com.vo.testVO" />
<!-- 상단에서 선언한 resultMap의 id를 적어준다. -->
<select id="testSelect" resultMap="test_resultMap">
select *
from testTable
where 1=1
</select>
parameterType
하나의 변수를 매개변수로 전달받을 때
<!-- 숫자형을 전달받아 사용할 때 -->
<select id="testSelect" parameterType="java.lang.Integer">
select count(*)
from testTable
where 1=1
and age = #{age}
</select>
<!-- 문자열을 전달받아 사용할 때 -->
<select id="testSelect" parameterType="java.lang.String">
select name
from testTable
where 1=1
and use = #{use}
</select>
<!-- 여러 변수를 전달할 때 -->
<select id="testSelect" parameterType="java.util.HashMap">
select *
from testTable
where 1=1
and use = #{use}
and name = #{name}
and age = #{age}
</select>
parameterMap
정해진 형태를 갖춰 매개변수를 전달받을 때
<!-- parameterMap을 선언해줘야 한다. -->
<!-- parameterMap을 구분할 수 있는 id와 경로(type)를 설정해줘야 한다. -->
<parameterMap id="test_parameterMap" type="test.project.com.vo.testVO" />
<!-- 상단에서 선언한 parameterMap의 id를 적어준다. -->
<!-- resultType 또는 resultMap 선언이 필수적이나, 아래의 예시를 마저 보도록 하자. -->
<select id="testSelect" parameterMap="test_parameterMap">
select *
from testTable
where 1=1
and type = #{type}
and use = #{use}
and age = #{age}
</select>
출처 : https://develop-is-reality.tistory.com/22
mybatis / parameter & result - Map & Type
mybatis를 사용할 때, parameterMap 및 parameterType, resultMap 및 resultType을 선언하여 사용한다. 이 친구들에 대해 알아보도록 하자. 간단하게 정리하면 다음과 같이 정리할 수 있다. parameterMap : 비즈니스
develop-is-reality.tistory.com
resultType에 넣을수 있는 값 정리
https://java119.tistory.com/45
[MyBatis] resultType에 넣을 수 있는 값 정리
resultType 문법 예시 쿼리 내용... 쿼리 내용... 쿼리 내용... 별칭(alias) 데이터 형태(data type) string String date Date map Map hashmap HashMap list List arraylist ArrayList decimal BigDecimal bigdecimal BigDecimal biginteger BigInteg
java119.tistory.com
728x90
'STUDY > DB SQL' 카테고리의 다른 글
[SQL] NOT NULL ENABLE / NOT NULL DISABLE (0) | 2023.06.08 |
---|---|
[MyBatis] ${} 와 #{} 차이점 (0) | 2023.05.25 |
[SQL] 오라클 ORA-01810: 형식 코드가 두 번 나타났습니다 (0) | 2023.03.30 |
[SQL] 오라클 날짜 검색 방법 총 정리 (0) | 2023.03.30 |
[SQL] 오라클 함수 생성·수정·삭제하기 (0) | 2023.03.27 |