Skip to main content

Mapper Interface

The generic BaseMapper interface provides a set of common database operation methods that utilize object mapping information to perform database operations.

1. Declare Entity Class
@Table("users")
public class User {
@Column(name = "id", primary = true, keyType = KeyTypeEnum.Auto)
private Long id;
@Column("name")
private String name;
...
}
2. Create Generic Mapper
// 1. Create Configuration
Configuration config = new Configuration();

// 2. Create Session
Session session = config.newSession(dataSource);
// OR
Session session = config.newSession(connection);

// 3. Create BaseMapper
BaseMapper<User> mapper = session.createBaseMapper(User.class);

In actual usage, the way to obtain a Session may vary depending on your project architecture. The above code demonstrates a primitive way to create a Session. You can choose the appropriate way to obtain a Session according to your project architecture. For details, please refer to: Framework Integration

Relevant Classes

  • net.hasor.dbvisitor.mapping.Table
  • net.hasor.dbvisitor.mapping.Column
  • net.hasor.dbvisitor.session.Configuration
  • net.hasor.dbvisitor.session.Session
  • net.hasor.dbvisitor.mapper.BaseMapper

User Guide

The BaseMapper interface provides several methods. The main scenarios are introduced below: