use of com.github.dreamroute.mybatis.pro.core.annotations.Id in project mybatis-pro by Dreamroute.
the class MapperUtil method createSqlFragment.
private void createSqlFragment() {
Map<String, String> values2Columns = new HashMap<>();
IdType pkType = new IdType();
PrimaryKey pk = new PrimaryKey();
Reflector r = new Reflector(entityCls);
ReflectionUtils.doWithFields(entityCls, field -> {
Column colAn = field.getAnnotation(Column.class);
String column = Optional.ofNullable(colAn).map(Column::value).orElse(SqlUtil.toLine(field.getName(), FIELDS_ALIAS_CACHE.get(entityCls)));
values2Columns.put(field.getName(), column);
Id idAn = field.getAnnotation(Id.class);
if (idAn != null) {
pkType.type = idAn.type();
pk.name = field.getName();
}
}, f -> isJavaBeanProp(r, f));
if (pkType.type == Type.IDENTITY) {
values2Columns.remove(pk.name);
}
List<String> columns = new ArrayList<>();
List<String> values = new ArrayList<>();
values2Columns.forEach((fieldName, column) -> {
columns.add(column);
values.add(fieldName);
});
this.insertColumns = columns.stream().collect(Collectors.joining(",", "(", ")"));
this.insertValues = values.stream().map(column -> "#{" + column + "}").collect(Collectors.joining(",", "(", ")"));
this.createInsertExcludeNullColumnsAndValues(columns, values);
this.createUpdateByIdColumns(columns, values);
this.createUpdateByIdExcludeNullColumns(columns, values);
}