本文整理汇总了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[]
};
}
示例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[]
};
}
示例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);
});
};
}
示例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[]
};
}
示例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());
});
};
}
示例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);
}
示例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);
}
示例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));
}
}
示例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);
}