springboot配置mongodb,處理資料有點 . 的情況
阿新 • • 發佈:2019-01-23
mongo中setMapKeyDotReplacement可設定用別的符號代替,多看原始碼就知道了,直接上程式碼:
@Configuration @ComponentScan @SpringBootApplication @EnableEurekaClient public class ReportApplication { @Autowired public MongoDbFactory mongoFactory; @Autowired public MongoMappingContext mongoMappingContext; @Bean public MappingMongoConverter mongoConverter() throwsException { DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoFactory); MappingMongoConverter mongoConverter = new MappingMongoConverter(dbRefResolver, mongoMappingContext); //this is my customization mongoConverter.setMapKeyDotReplacement("-"); mongoConverter.afterPropertiesSet(); returnmongoConverter; } public static void main(String[] args) { SpringApplication.run(ReportApplication.class, args); } }