2016-08-30 1 views
0

null이 아닌 경우에만 null 값을 삽입하려고합니다. null 인 경우, DB에 디폴트 치를 삽입합니다.myBatis는 조건부로 null 값을 삽입하지 않습니다.

<insert id ="inventorySave"> 
<[CDATA[ 

INSET INTO inventory 
(itemname,amount,id,level) 
values 
]] 
<foreach item="inventory" collection="inventoryies" separator=","> 
<[CDATA[ 
(#{inventory.itemName},#{inventory.amount}, #{inventory.id}, #{inventory.level}) 
]] 
</foreach> 
</insert> 

내가 '수준'에 대한 값을 확인 할 유효한 문자열입니다, '보통', '중요', '심각한'. 빈 문자열 또는 널 (null) 값이있는 경우에는 any를 지정하지 말고 데이터베이스가 기본값을 삽입하도록 결정해야합니다.

누구든지 조건부로 레코드를 삽입하는 방법을 알려주십시오.

답변

1

는 해당 jdbcType데이터베이스 열 유형 당신이 무엇을 기대 acheive하는 모든 dymanic 값을 지정합니다. 당신의 위의 질의 변화로 예를 들어

level 아래와 유사하게 다른 엔티티로 :

#{inventory.level,jdbcType=NVARCHAR} 
    //assuming the equivalent column type in database for itemname is varchar.