In the previous section, we declared our configuration using JavaConfig and compared it side-by-side with an XML-based configuration. In this section, we will discuss the remaining layers of our application.
Table of Contents
Click on a link to jump to that section:
Running the application
- HTML Mockup
- Thymeleaf Integration
- Clone from GitHub
- Create the Database
- Run with Maven and Tomcat 7
- Run with Maven and Jetty 8
- Import to Eclipse
- Validate with W3C
Here we'll discuss the Domain, Repository, Service and Controller layers.
DomainOur domain layer consists of two simple classes: User.java and Role.java. If you'd been following my previous tutorials, you will notice that these are the same domain classes we'd been using before. Both classes had been annotated with @Entity which means these are JPA entities and will be persisted to a database.
These classes represent a user with the following properties: first name, last name, username, role, and password (we're not actively using the password field).
For role, we only have two values: an admin or a regular user.
ControllerOur controller is a standard controller providing CRUD requests. The most important lines here are the following:
These lines adds three attributes to the model:
- users - contains all users
- commanduser - the form backing object or the command object of the form
- usertype - an attribute to determine if the request is a new user or existing user
RepositoryWe have created two repositories: UserRepository and RoleRepository(not shown). We will be using UserRepository as our primary data access object. Notice we have declared a custom method findByUsername but beyond that, this repository is pretty much standard. UserRepository.java
ServiceOur service layer basically delegates to the repository. It provides an extra logic to filter out duplicate usernames. UserService.java
NextIn the next section, we will study how to build and run our application. We will be using Maven, Tomcat, and Jetty to run the app. We'll also study how to import the project in Eclipse. Click here to proceed.
Share the joy:
Subscribe by reader Subscribe by email Share