Databases Reference
In-Depth Information
//Loading application context
AnnotationConfigWebApplicationContext rootContext = new
AnnotationConfigWebApplicationContext();
rootContext.register(ApplicationContext.class);
//Dispatcher servlet
ServletRegistration.Dynamic dispatcher = servletContext.
addServlet("dispatcher", new DispatcherServlet(rootContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
//Context loader listener
servletContext.addListener(new ContextLoaderListener(rootCont
ext));
}
}
Implementing CRUD functionality for an
entity
We have now configured the Spring application context and configured our web
application to load it during startup. We will now implement CRUD functions
for a simple entity. Our example application is used to view and manage contact
information, and we can implement it by following these steps:
1.
Create a domain model.
2.
Create a repository for an entity.
3.
Implement CRUD functions.
This chapter describes only such parts of our application that
are required to understand how Spring Data JPA works.
Domain model
The domain model of our application consists of two classes: Contact and Address .
This subsection will address the following matters:
• The information content of each class
• How we can create new objects by using the builder pattern (see also:
Effective Java ( Second Edition ), Joshua Bloch , Addison-Wesley )
• How we can update the information of an object
 
Search WWH ::




Custom Search