12 Aralık 2017 Salı

SpringData Jdbc Jdbc BeanPropertyRowMapper Sınıfı

Giriş
Açıklaması şöyle. Yani RowMapper arayüzünü kullanmak daha iyi
To have tight integration between Java and ResultSet of JDBC, Spring JDBC has a RowMapper interface. A developer can either create a custom class or use BeanPropertyRowMapper, which reduces the boilerplate; however, the entity should have a public getter and setter; it might get an encapsulation issue besides it provides convenience rather than high performance. For best performance, consider using a custom RowMapper implementation.
Örnek
Elimizde bir model sınıfı olsun.
public class FooModel {

  private Long id;
  private String name;

  public InvModel() {
    super();
  }

}
Şöyle yaparız.
RowMapper<InvModel> MAPPER = BeanPropertyRowMapper.newInstance(FooModel.class);

Hiç yorum yok:

Yorum Gönder