參考了一下網上的帖子 https://stackoverflow.com/questions/23517977/spring-boot-mongodb-how-to-remove-the-class-column
簡單的方式是:
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper; import org.springframework.data.mongodb.core.convert.MappingMongoConverter; @Configuration public class MongoDBConfig implements InitializingBean { // 參考:https://stackoverflow.com/questions/23517977/spring-boot-mongodb-how-to-remove-the-class-column @Autowired @Lazy private MappingMongoConverter mappingMongoConverter; @Override public void afterPropertiesSet() { mappingMongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null)); } }