修改DefaultMongoTypeMapper
/**
* 更改默认的 MongoDB 映射转换器,更改'_class'字段
*
* @param factory MongoDB 工厂对象
* @param context MongoDB 映射上下文
* @param beanFactory springBean 工厂
* @return MongoDB 映射转换器
*/
@Bean
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, MongoMappingContext context, BeanFactory beanFactory) {
DbRefResolver defaultDbRefResolver = new DefaultDbRefResolver(factory);
MappingMongoConverter mappingMongoConverter = new MappingMongoConverter(defaultDbRefResolver, context);
try {
mappingMongoConverter.setCustomConversions(beanFactory.getBean(CustomConversions.class));
} catch (NoSuchBeanDefinitionException ignore) {
}
///修改DefaultMongoTypeMapper的传参值,是什么_class就被改为什么,时值为null时,则没有_class字段
mappingMongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
return mappingMongoConverter;
}