當前位置: 首頁>>代碼示例>>Java>>正文


Java MongoOperations.insert方法代碼示例

本文整理匯總了Java中org.springframework.data.mongodb.core.MongoOperations.insert方法的典型用法代碼示例。如果您正苦於以下問題:Java MongoOperations.insert方法的具體用法?Java MongoOperations.insert怎麽用?Java MongoOperations.insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.data.mongodb.core.MongoOperations的用法示例。


在下文中一共展示了MongoOperations.insert方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.springframework.data.mongodb.core.MongoOperations; //導入方法依賴的package包/類
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg"));
		operations.insert(new Image("3",
			"bazinga.png"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:20,代碼來源:InitDatabase.java

示例2: init

import org.springframework.data.mongodb.core.MongoOperations; //導入方法依賴的package包/類
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg", "greg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg", "greg"));
		operations.insert(new Image("3",
			"bazinga.png", "phil"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:20,代碼來源:InitDatabase.java

示例3: initializeUsers

import org.springframework.data.mongodb.core.MongoOperations; //導入方法依賴的package包/類
@Bean
CommandLineRunner initializeUsers(MongoOperations operations) {
	return args -> {
		operations.dropCollection(User.class);

		operations.insert(
			new User(
				null,
				"greg", "turnquist",
				new String[]{"ROLE_USER", "ROLE_ADMIN"}));
		operations.insert(
			new User(
				null,
				"phil", "webb",
				new String[]{"ROLE_USER"}));

		operations.findAll(User.class).forEach(user -> {
			System.out.println("Loaded " + user);
		});
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:22,代碼來源:InitUsers.java

示例4: init

import org.springframework.data.mongodb.core.MongoOperations; //導入方法依賴的package包/類
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg", "greg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg", "greg"));
		operations.insert(new Image("3",
			"bazinga.png", "greg"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:20,代碼來源:InitDatabase.java

示例5: init

import org.springframework.data.mongodb.core.MongoOperations; //導入方法依賴的package包/類
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg"));
		operations.insert(new Image("3",
			"bazinga.png"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:18,代碼來源:InitDatabase.java

示例6: main

import org.springframework.data.mongodb.core.MongoOperations; //導入方法依賴的package包/類
public static void main(String[] args) throws UnknownHostException {
    // MongoOperations mongoTemplate = new MongoTemplate(new MongoClient(), "sdcuike");
    MongoCredential mongoCredential = MongoCredential.createCredential("mongo", "sdcuike", "mongo".toCharArray());
    MongoClient mongoClient = new MongoClient(new ServerAddress("127.0.0.1", 27017), Arrays.asList(mongoCredential));

    MongoOperations mongoTemplate = new MongoTemplate(mongoClient, "sdcuike");
    mongoTemplate.insert(new Person("doctor", 1236666, UUID.randomUUID().toString()));
    List<Person> list = mongoTemplate.findAll(Person.class);

    System.out.println(list.size());
    list.forEach(System.out::println);
    // mongoTemplate.dropCollection(Person.class);

}
 
開發者ID:sdcuike,項目名稱:book-reading,代碼行數:15,代碼來源:MongoApp.java

示例7: prepare

import org.springframework.data.mongodb.core.MongoOperations; //導入方法依賴的package包/類
@Override
public void prepare(Description description) {
    MongoOperations mongoOperation = (MongoOperations) ApplicationContextProvider.getApplicationContext().getBean("mongoTemplate");

    Veiculo veiculo = createVeiculo();
    Condutor proprietario = veiculo.getProprietario();

    mongoOperation.insert(proprietario);
    mongoOperation.insert(veiculo);
    
    OBJECT.set(veiculo);
}
 
開發者ID:UNGPublic,項目名稱:sampleng-backend,代碼行數:13,代碼來源:VeiculoResourceCondition.java

示例8: insert

import org.springframework.data.mongodb.core.MongoOperations; //導入方法依賴的package包/類
/**
 * テストデータをMongoDBに登録します。
 * @param operations {@link MongoOperations}
 * @param executables 登録するJSONデータ
 * @param config {@link MongoInitialize}
 */
protected void insert(MongoOperations operations, Object executables, MongoInitialize config) {
    L.info(Strings.substitute(R.getString("I-MONGO-TEST#0003"), Maps.hash("value", executables.toString())));
    if (executables.getClass().isArray()) {
        List<Object> gen = Lists.gen((Object[])executables);
        operations.insert(gen, findCollectionName(config));
    } else {
        operations.insert(executables, findCollectionName(config));
    }
}
 
開發者ID:ctc-g,項目名稱:sinavi-jfw,代碼行數:16,代碼來源:TestMongoKeeper.java

示例9: prepare

import org.springframework.data.mongodb.core.MongoOperations; //導入方法依賴的package包/類
@Override
public void prepare(Description description) {
	MongoOperations mongoOperation = Application.getMongoOperations();

	Condutor proprietario = createProprietario();

	mongoOperation.insert(proprietario);
	
	OBJECT.set(proprietario);

}
 
開發者ID:UNGPublic,項目名稱:sampleng-backend,代碼行數:12,代碼來源:CondutorResourceCondition.java


注:本文中的org.springframework.data.mongodb.core.MongoOperations.insert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。