반응형

잡담.

삽질의 연속

인터넷에도 퍼즐처럼 흩어져 있어서 하루종일 시블시블거리면서 찾은 정보.

 

 

## javaType을 설정하면 Null 값으로 나오는 데이터를 Java 타입에 맞게 Default 값으로 뽑아준다

## log Level이 debug이면, 17004 에러가 계속 발생한다. Info로 바꿀것.

 

1. mybatis-config > typeHandler 설정

 

<!-- 참고: Type Alias 보다 아래에 둘것 -->

<typeHandlers>
        <typeHandler handler="com.패키지위치.MyLongTypeHandler" jdbcType="LONGVARCHAR" javaType="java.lang.String"/>
</typeHandlers>

 

 

 

2. SQL XML > resultMap 추가

 - sql 부분

<resultMap type="MyVO" id="MyBean">
<result property="contents"  column="contents"  jdbcType="LONGVARCHAR" javaType="java.lang.String"  
  typeHandler="com.패키지위치.MyLongTypeHandler"/>
</resultMap>

 

 

 

3. Handler 클래스 추가

@MappedJdbcTypes(JdbcType.LONGVARCHAR)

public class MyLongTypeHandler implements TypeHandler {

@Override

public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)

throws SQLException {

String s = (String) parameter;

StringReader reader = new StringReader(s);

ps.setCharacterStream(i, reader, s.length());

}

 

@Override

public Object getResult(ResultSet rs, String columnName) throws SQLException {

return rs.getString(columnName);

}

 

@Override

public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {

return cs.getString(columnIndex);

}

}

 

 

 

4. 참조

 - http://mybatis.github.io/mybatis-3/ko/configuration.html 의 typeHandlers 부분 참조

반응형

WRITTEN BY
데르벨준

,