1. 程式人生 > >springboot配置mongodb,處理資料有點 . 的情況

springboot配置mongodb,處理資料有點 . 的情況

mongo中setMapKeyDotReplacement可設定用別的符號代替,多看原始碼就知道了,直接上程式碼:

@Configuration
@ComponentScan
@SpringBootApplication
@EnableEurekaClient
public class ReportApplication {

   @Autowired
public MongoDbFactory mongoFactory;

   @Autowired
public MongoMappingContext mongoMappingContext;

   @Bean
public MappingMongoConverter mongoConverter() throws 
Exception { DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoFactory); MappingMongoConverter mongoConverter = new MappingMongoConverter(dbRefResolver, mongoMappingContext); //this is my customization mongoConverter.setMapKeyDotReplacement("-"); mongoConverter.afterPropertiesSet(); return
mongoConverter; } public static void main(String[] args) { SpringApplication.run(ReportApplication.class, args); } }