在spring-data-mongo中,这个界面的功能是否还可以扩展?
我想要的是在mongodb中保存CamelCaseToUnderline并查询UnderlineToCamelCase。
我看到了部分源代码,它有一个最终的FieldNamingStrategy.if我想将它进行成本化,它必须在实例化之前如何实现?
public class BasicMongoPersistentProperty extends AnnotationBasedPersistentProperty<MongoPersistentProperty> implements MongoPersistentProperty {
....
private final FieldNamingStrategy fieldNamingStrategy;
public BasicMongoPersistentProperty(Field field, PropertyDescriptor propertyDescriptor, MongoPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder, FieldNamingStrategy fieldNamingStrategy) {
super(field, propertyDescriptor, owner, simpleTypeHolder);
this.fieldNamingStrategy = fieldNamingStrategy == null ? PropertyNameFieldNamingStrategy.INSTANCE : fieldNamingStrategy;
if (isIdProperty() && getFieldName() != ID_FIELD_NAME) {
LOG.warn("Customizing field name for id property not allowed! Custom name will not be considered!");
}
}
...
}
答案 0 :(得分:0)
嗨,这是来自春季启动附录
# MONGODB (MongoProperties)
spring.data.mongodb.field-naming-strategy= # Fully qualified name of the FieldNamingStrategy to use
你有开箱即用的策略
CamelCaseSplittingFieldNamingStrategy
CamelCaseAbbreviatingFieldNamingStrategy
SnakeCaseFieldNamingStrategy
如果这些不适合您的需求,请随意扩展它们