我在快速启动应用程序中使用了 spring-data-mongodb 1.2.1-RELEASE。它工作正常,我可以连接到 mongo db 我可以创建、更新和删除集合现在我想将 wicket-framework 与这个应用程序集成。
领域类
@Document
public class Student
{
@Id
private String id;
private String firstName;
private int age;
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
}
学生存储库类
@Repository
public class StudentService
{
@Autowired
MongoTemplate mongoTemplate;
@Override
public void create(Student student)
{
mongoTemplate.insert(student);
}
@Override
public void update(Query query, Update update)
{
mongoTemplate.updateFirst(query, update, Student.class);
}
@Override
public List<Student> findAll()
{
List<Student> students = mongoTemplate.findAll(Student.class);
logger.debug("Student: {}", students);
return students;
}
@Override
public void delete(Student student)
{
mongoTemplate.remove(student);
}
@Override
public void deleteAll()
{
Query searchUserQuery = new Query(Criteria.where("age").gt(0));
mongoTemplate.remove(searchUserQuery, Student.class);
}
}
Mongo配置类
@Configuration
@EnableMongoRepositories
@ComponentScan(basePackageClasses = {MongoDBApp.class})
@PropertySource("classpath:application.properties")
public class MongoConfiguration extends AbstractMongoConfiguration
{
@Override
protected String getDatabaseName()
{
return "demo";
}
@Override
public Mongo mongo() throws Exception
{
return new Mongo("localhost", 27017);
}
@Override
protected String getMappingBasePackage()
{
return "mypackage";
}
}
Mongo Db 主类
public class MongoDBApp
{
static final Logger logger = LoggerFactory.getLogger(MongoDBApp.class);
public static void main(String[] args)
{
logger.info("Demo application");
ApplicationContext context = new AnnotationConfigApplicationContext(MongoConfiguration.class);
StudentService studentService = context.getBean(StudentService.class);
Student student = new Student();
student.setFirstName("foo");
student.setAge(24);
studentService.create(student);
List<Student> students = studentService.findAll();
logger.info("No. of students: {}", students.size());
studentService.delete(student);
logger.info("Deleted student: {}", student);
}
}
pom.xml 中的依赖项
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
对于此代码,我想与 wicket 框架集成。
请帮我怎么做?