我现在正在使用Tapestry 5.4beta6,我可以看到有tapestry-mongodb模块。有什么例子我如何在应用程序中使用它?我在github上找到了前一个模块,但只有一个注释,模块是核心框架的一部分,但没有文档或示例......
答案 0 :(得分:0)
tapestry-mongodb 只是包装了MongoDB Java驱动程序的初始化。 您可以自由使用您喜欢的任何POJO包装纸;有很多:
我从tapestry-mongodb测试中采用了这个例子,它使用Jongo作为ORM:
<强>模块强>
public class MongoDBTestModule
{
public static void contributeApplicationDefaults(MappedConfiguration<String, String> configuration)
{
configuration.add(MongoDBSymbols.DEFAULT_DB_NAME, "TapestryMongoTest");
}
public static void contributeMongoDBSource(OrderedConfiguration<ServerAddress> configuration)
{
try
{
configuration.add("test", new ServerAddress("localhost", 12345));
}
catch (UnknownHostException e)
{
throw new RuntimeException(e);
}
}
}
人员实体:
package org.apache.tapestry5.internal.mongodb;
import org.bson.types.ObjectId;
import java.util.Date;
/**
*
*/
public class People
{
private ObjectId _id;
private String name;
private String surname;
private Date birthDate;
public ObjectId get_id() {
return _id;
}
public void set_id(ObjectId _id) {
this._id = _id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
}
实际测试代码
@Inject
MongoDB mongoDB;
void test() {
// ...
org.jongo.Jongo jongo = new Jongo(mongoDB.getDefaultMongoDb());
org.jongo.MongoCollection peoples = jongo.getCollection("peoples");
// ...
}