com.manager.dao.sql.VcardDAO.xml




	
	
		
		
		
		
		
		
	
	
	
		insert into VcardTable(name, addr, cell, tel, fax, email)
			values(#name#, #addr#, #cell#, #tel#, #fax#, #email#)
	
	
		update VcardTable
			set addr=#addr#,cell=#cell#,tel=#tel#,fax=#fax#,email=#email#
			where name=#name#
	
	



예제로 설명하겠다.

<sqlMap namespace="vcard">

sqlMap으로 선언되며 

<typeAlias alias="VcardInformation" type="com.manager.vo.vcard.VcardInformation"/>

뒤에있을 resultMap에 사용할 class를 정의한다. 해당클래스에는 Xml파싱을 위한 어노테이션들이 기록되어있다. (다음장에서 설명)

<resultMap id="resultMapVcardInformation" class="VcardInformation">

VcardInformation 클래스의 인자를 sql쿼리에 쓰일 데이터와 맵핑해준다. resultMap은 select문 등 칼럼 맵핑이 필요할때 사용된다.

ex) <result property="varName" column="DB_NAME"/>

varName이라는 변수를 DB_NAME 칼럼에 맵핑

<select id="select" resultMap="resultMapVcardInformation" parameterClass="VcardInformation">

select

name, addr, cell, tel, fax, email

from

VcardTable

</select>

".select"로 호출된다. 

select시  parameterClass는 위에 선언한 resultMap의 class의 선언 어노테이션에 맞는 값을 찾아서 넣는다.

Column  | -> |StringVal

NAME칼럼의 DBVAL1 -> property에 해당하는 class의 어노테이션을찾아맵핑 -> name(변수)로 들어오게 된다.

말이 어려운데 맵핑 맵핑을 잘생각해보면 이해할 수 있다.

구현해보면 더 쉽게 이해할 수 있고..


<insert id="insert" parameterClass="VcardInformation">

insert into VcardTable(name, addr, cell, tel, fax, email)

values(#name#, #addr#, #cell#, #tel#, #fax#, #email#)

</insert>

마찬가지로 ".insert"로 선언된다.

parameterClass에 VcardInformation 객체로 되어있는데 필요한경우 HashMap, String 등 간단하게 사용도 가능하다.

VcardInformation 객체의 내부선언된 어노테이션의 변수에 ##으로 변수를 삽입, sql문에 사용 할 수 있다.


<select id="count" resultClass="Integer">

select count(uid) as total from VcardTable where name=#name#

</select>

위의 예제와 비슷하나 이것은 리턴값이 integer이다. resultClass를 보면 쉽게 구분 가능한데, 갯수를 구하여 리턴해야 하기때문에 굳이  객체선언 등 필요가 없다. 

이번 포스트는 좀.. 많이 난해하다. 남한테 설명하기란 어렵구나


'DB > iBatis' 카테고리의 다른 글

iBatis구현 7 - xxxDAO.java  (0) 2012.03.29
iBatis 구현 - 6 Xml맵핑- .vo.xxx.java  (0) 2012.03.29
iBatis 구현 - 4 sqlMapConfig.xml  (0) 2012.03.29
iBatis에서 HashMap의 활용  (2) 2012.03.29
iBatis 구현 - 3 xxx-servlet.xml 작성  (0) 2012.03.28

+ Recent posts