SELECT name FROM TABLE and resultMap like this SELECT name FROM TABLE and resultMap like this SELECT name FROM TABLE and resultMap like this

mybatis typeHandler not work

1k views Asked by At

I have a sql like this

<select id="getData" parameterType="map" resultMap="dataMapper">
  SELECT name FROM TABLE
</select>

and resultMap like this

<resultMap id="dataMapper" type="String">
    <result property="data" column="name" typeHandler="xxx.NameTypeHandler" />
</resultMap>

NameTypeHandler

public class NameTypeHandler implements TypeHandler<String> {

  @Override
  public void setParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
    // TODO Auto-generated method stub
  }

  @Override
  public String getResult(ResultSet rs, String columnName) throws SQLException {
    return "test" + rs.getString(columnName);
  }

  @Override
  public String getResult(ResultSet rs, int columnIndex) throws SQLException {
    return "test" + rs.getString(columnIndex);
  }

  @Override
  public String getResult(CallableStatement cs, int columnIndex) throws SQLException {
    return "test" + cs.getString(columnIndex);
  }
}

but it never works with the handler

can I use like this?

0

There are 0 answers