Mapper Interface
Hint
This article is generated by AI translation.
The generic BaseMapper interface offers common database operations using entity mapping metadata.
1) Define an entity
@Table("users")
public class User {
@Column(name = "id", primary = true, keyType = KeyTypeEnum.Auto)
private Long id;
@Column("name")
private String name;
...
}
2) Create BaseMapper
// 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);
Quick guide
BaseMapper covers several scenarios:
- Basics: CRUD and paging.
- Fluent API: use the Fluent API on the mapper.
- Mapper Files: Used to define a command, which can be referenced on the corresponding Mapper interface.