3

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?

byron
  • 41
  • 3
  • 2
    I'm suprised that you can actually map a String that way. You learn every day... Anyway, if you don't use a String, but a wrapper type, for example a simple Java bean with a single String property, it works fine. Perhaps no handler is called for simple types? – Florian Schaetz Mar 24 '16 at 09:42
  • 1
    Yep, the suggest what u told works fine. i just want to know can this way work by change some setting. thanks for your reply. – byron Mar 28 '16 at 09:10

0 Answers0