标签:tis ble err 否则 lob bsp statement handlers jdbc
配置注册
mybatis.type-handlers-package=com.patsnap.inno.doc.core.handler
使用
@MappedJdbcTypes({JdbcType.CLOB}) @MappedTypes({String.class}) public class TextHandler implements TypeHandler<String> { private int max = 300; @Override public void setParameter(PreparedStatement preparedStatement, int i, String s, JdbcType jdbcType) throws SQLException { preparedStatement.setString(i,s); } @Override public String getResult(ResultSet rs, String columnName) throws SQLException { String text = rs.getString(columnName); if (StringUtils.isNotEmpty(text)) { return text.substring(0, text.length() > max ? max : text.length()); } else { return ""; } } @Override public String getResult(ResultSet rs, int columnIndex) throws SQLException { String text = rs.getString(columnIndex); if (StringUtils.isNotEmpty(text)) { return text.substring(0, text.length() > max ? max : text.length()); } else { return ""; } } @Override public String getResult(CallableStatement cs, int columnIndex) throws SQLException { String text = cs.getString(columnIndex); if (StringUtils.isNotEmpty(text)) { return text.substring(0, text.length() > max ? max : text.length()); } else { return ""; } } }
<result property="summary" column="summary" typeHandler="com.patsnap.inno.doc.core.handler.TextHandler" jdbcType="CLOB"/>
注意 如果是集成BaseTypeHandler,那么将会在所有符合条件的字段上起作用。
所以,除非特么全局通用的TypeHandler,否则不要使用BaseTypeHandler.
标签:tis ble err 否则 lob bsp statement handlers jdbc
原文地址:http://www.cnblogs.com/tonyq/p/7890376.html