티스토리 뷰
<select id="get" parameterType="map" resultMap="resultMap"> SELECT * FROM 테이블명 <where> <if test="파라미터 != null and 파라미터 == 'A'"> AND 필드명 = #{파라미터} </if> </where> </select>
위와 같은 쿼리 실행시 NumberFormatException이 발생 한다면
아래와 같이 코드를 수정 하면 해결 될 것이다.
<select id="get" parameterType="map" resultMap="resultMap"> SELECT * FROM 테이블명 <where> <if test="파라미터 != null and (파라미터 eq 'A'.toString())"> AND 필드명 = #{파라미터} </if> </where> </select>
OR
<select id="get" parameterType="map" resultMap="resultMap"> SELECT * FROM 테이블명 <where> <if test="파라미터 != null and 파라미터.equals('A')"> AND 필드명 = #{파라미터} </if> </where> </select>
보너스 (대소문자 무시)
<select id="get" parameterType="map" resultMap="resultMap"> SELECT * FROM 테이블명 <where> <if test="파라미터 != null and 파라미터.equalsIgnoreCase('A')"> AND 필드명 = #{파라미터} </if> </where> </select>
'프로그래밍 > Java' 카테고리의 다른 글
[mybatis] java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransactionFactory.newTransaction(Ljava/sql/Connection;)Lorg/apache/ibatis/transaction/Transaction; (2) | 2012.06.05 |
---|---|
[mybatis] if 에서 문자열 비교시 NumberFormatException 해결 방법 (2) | 2011.08.04 |
[SpringFramework] 한글 문제 (0) | 2011.07.29 |
HTTP Post 요청 (0) | 2010.08.13 |
[ibatis] 동적 쿼리 실행 AutoResultMap 에러 (0) | 2010.05.28 |
HTTP요청 인지 HTTPS 요청인지 확인하는 방법 (1) | 2010.05.19 |
- TAG
- IF, mybatis, NumberFormatException
공지사항
- Total
- 430,183
- Today
- 63
- Yesterday
- 183