use of org.apache.ibatis.reflection.Reflector in project mybatis-pro by Dreamroute.
the class ClassUtil method getAllFields.
/**
* 获取实体所有JavaBean属性:
* <ol>
* <li>JavaBean属性</li>
* <li>未被@Transient标记</li>
* </ol>
*/
public static Set<Field> getAllFields(Class<?> cls) {
Field[] fs = getFields(cls);
Reflector r = new Reflector(cls);
return Arrays.stream(fs).filter(f -> isJavaBeanProp(r, f)).collect(Collectors.toSet());
}
use of org.apache.ibatis.reflection.Reflector 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);
}
use of org.apache.ibatis.reflection.Reflector in project yyl_example by Relucent.
the class ReflectorExample method main.
public static void main(String[] args) {
Reflector reflector = new Reflector(PrivateBean.class);
// 获得对应属性,大小写不敏感
String property1 = reflector.findPropertyName("value");
String property2 = reflector.findPropertyName("VALUE");
String property3 = reflector.findPropertyName("Value");
System.out.println(property1);
System.out.println(property2);
System.out.println(property3);
}
Aggregations