5.3 Builder API
LambdaTemplate is the core class of dbVisitor's Builder API, building SQL statements programmatically and automatically handling database dialect differences.
Choose a Mode First
| Mode | Requires object mapping | Best for |
|---|---|---|
| Entity mode | Yes | Entity classes and method references such as User::getName. |
| Mapped Map Mode | Yes | Table mapping exists, but row data is carried by Map. |
| Freedom Map Mode | No | Direct table names, column names, and Map values. |
Entity mode and Mapped Map Mode require Object Mapping. Freedom Map Mode does not need entity mapping.
@Table("users")
public class User {
@Column(value = "id", primary = true, keyType = KeyType.Auto)
private Long id;
@Column("name")
private String name;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
LambdaTemplate lambda = new LambdaTemplate(dataSource);
// Query example
List<User> users = lambda.query(User.class)
.eq(User::getName, "alice")
.queryForList();
How to obtain a LambdaTemplate depends on your project architecture. See Framework Integration for details.
Principle
Build operations through the insert, update, delete, query, and freedom series of methods. Developers describe SQL logic programmatically; at runtime, dialect-specific SQL is generated automatically and executed via JdbcTemplate.
User Guide
- Data Writes, inserts, updates, and deletes.
- Query, query data.
- Where Builder, build complex query conditions for Update/Delete/Query.
- Group By, GROUP BY grouped queries.
- Order By, ORDER BY query sorting.
- Mapped Map Mode, reuse object mapping while using Map as the row carrier.
- Freedom Map Mode, use table and column names directly without object mapping.
Data Writes
- Insert: insert entities or multiple records; see Write Conflicts for duplicate handling.
- Update: update selected fields, use a sample, or overwrite a row.
- Delete: delete records matching the conditions.
Updates and deletes reject empty conditions by default. Call allowEmptyWhere() explicitly to operate on all records. See Builder API Differences for affected counts and readback behavior by data source.