add table cols

This commit is contained in:
Shaun Chyxion 2017-07-19 22:41:51 +08:00
parent 4e12de07ab
commit 0e55d16fa4

View File

@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import me.chyxion.tigon.util.WordUtils;
import me.chyxion.tigon.mybatis.PrimaryKey;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ReflectionUtils;
/**
@ -88,10 +89,20 @@ public abstract class BaseModel<PK> extends MappableSupport implements Mappable
* @return cols model cols
*/
public Collection<String> cols() {
return cols(null);
}
/**
* return model cols
* @param table table
* @return cols model cols
*/
public Collection<String> cols(final String table) {
Map<String, Object> mapModel = toMap();
List<String> cols = new ArrayList<String>(mapModel.size());
for (String field : mapModel.keySet()) {
cols.add(fieldToCol(field));
final String col = fieldToCol(field);
cols.add(StringUtils.isNotBlank(table) ? table + "." + col : col);
}
return cols;
}