use of com.mendmix.mybatis.metadata.TableMetadata in project jeesuite-libs by vakinge.
the class UpdateBuilder method buildSQL.
@Override
String buildSQL(EntityMetadata entityMapper, boolean selective) {
// 从表注解里获取表名等信息
TableMetadata tableMapper = entityMapper.getTable();
Set<ColumnMetadata> columnMappers = entityMapper.getColumns();
String idColumn = null;
String idProperty = null;
StringBuilder set = new StringBuilder();
set.append("<trim prefix=\"SET\" suffixOverrides=\",\">");
for (ColumnMetadata column : columnMappers) {
if (!column.isUpdatable()) {
continue;
}
if (column.isId()) {
idColumn = column.getColumn();
idProperty = column.getProperty();
} else {
String expr = SqlTemplate.wrapIfTag(column.getProperty(), column.getColumn() + "=#{" + column.getProperty() + "}", !selective);
set.append(expr);
if (!selective)
set.append(",");
}
}
if (!selective)
set.deleteCharAt(set.length() - 1);
set.append("</trim>");
String sql = String.format(SqlTemplate.UPDATE_BY_KEY, tableMapper.getName(), set.toString(), idColumn, idProperty);
return sql;
}
Aggregations