You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/site/markdown/docs/insert.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,66 @@ Notice the `map` method. It is used to map a database column to an attribute of
44
44
5.`map(column).toPropertyWhenPresent(property, Supplier<?> valueSupplier)` will insert a value from the record into a column if the value is non-null. The value of the property will be bound to the SQL statement as a prepared statement parameter. This is used to generate a "selective" insert as defined in MyBatis Generator.
45
45
6.`map(column).toRow()` will insert the record itself into a column. This is appropriate when the "record" is a simple class like Integer or String.
46
46
47
+
### Mapped Columns
48
+
Starting in version 2.0.0 there are two new methods:
49
+
50
+
1.`withMappedColumn(SqlColumn)` that will map a database column to a Java property based on a property name that can
51
+
be configured in an `SQLColumn`.
52
+
2.`withMappedColumnWhenPresent(SqlColumn, Supplier<T>)` that will map a database column to a Java property based on a
53
+
property name that can be configured in an `SQLColumn`. The insert statement will only contain the mapped column when
54
+
the Supplier returns a non-null value (this method is for single record inserts only).
55
+
56
+
This will allow you to configure mappings in a single place (the `SqlColumn`) and reuse them in multiple insert
57
+
statements. For example:
58
+
59
+
```java
60
+
publicfinalclassPersonDynamicSqlSupport {
61
+
publicstaticfinalPerson person =newPerson();
62
+
publicstaticfinalSqlColumn<Integer> id = person.id;
0 commit comments