码迷,mamicode.com
首页 > 数据库 > 详细

mongo db 去除 _class 字段

时间:2019-09-11 19:52:49      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:ltm   idt   ini   init   try   ret   title   one   pem   

  1. import org.springframework.beans.factory.BeanFactory;
  2. import org.springframework.beans.factory.NoSuchBeanDefinitionException;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.data.convert.CustomConversions;
  6. import org.springframework.data.mongodb.MongoDbFactory;
  7. import org.springframework.data.mongodb.core.convert.DbRefResolver;
  8. import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
  9. import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
  10. import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
  11. import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
  12.  
  13. /**
  14. * Create by JIUN·LIU at 2018/7/24
  15. */
  16.  
  17. @Configuration
  18. public class MongoConfig {
  19.  
  20. @Bean
  21. public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, MongoMappingContext context, BeanFactory beanFactory) {
  22. DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
  23. MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, context);
  24. try {
  25. mappingConverter.setCustomConversions(beanFactory.getBean(CustomConversions.class));
  26. } catch (NoSuchBeanDefinitionException ignore) {
  27. }
  28.  
  29. // Don‘t save _class to mongo
  30. mappingConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
  31.  
  32. return mappingConverter;
  33. }
  34.  
  35. }

mongo db 去除 _class 字段

标签:ltm   idt   ini   init   try   ret   title   one   pem   

原文地址:https://www.cnblogs.com/lykbk/p/wefsefsef.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!