Created
December 19, 2013 14:42
-
-
Save enterprisesaas/8040143 to your computer and use it in GitHub Desktop.
MongoDB annotated user using Spring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package model; | |
| import org.springframework.data.annotation.Id; | |
| import org.springframework.data.mongodb.core.mapping.Document; | |
| import java.io.Serializable; | |
| import java.util.UUID; | |
| /** | |
| * User | |
| * User: David King | |
| */ | |
| @Document(collection="users") | |
| public class User implements Serializable { | |
| @Id | |
| private String id; | |
| private String firstName; | |
| private String lastName; | |
| private String email; | |
| public User() { | |
| setId(UUID.randomUUID().toString()); | |
| } | |
| public User(String id, String firstName, String lastName, String email) { | |
| this.id = id; | |
| this.firstName = firstName; | |
| this.lastName = lastName; | |
| this.email = email; | |
| } | |
| public String getId() { | |
| return id; | |
| } | |
| public void setId(String id) { | |
| if (null != id) { | |
| this.id = id; | |
| } | |
| } | |
| public String getFirstName() { | |
| return firstName; | |
| } | |
| public void setFirstName(String firstName) { | |
| this.firstName = firstName; | |
| } | |
| public String getLastName() { | |
| return lastName; | |
| } | |
| public void setLastName(String lastName) { | |
| this.lastName = lastName; | |
| } | |
| public String getEmail() { | |
| return email; | |
| } | |
| public void setEmail(String email) { | |
| this.email = email; | |
| } | |
| @Override | |
| public boolean equals(Object o) { | |
| if (this == o) return true; | |
| if (o == null || getClass() != o.getClass()) return false; | |
| User user = (User) o; | |
| if (!email.equals(user.email)) return false; | |
| if (!firstName.equals(user.firstName)) return false; | |
| if (!id.equals(user.id)) return false; | |
| if (!lastName.equals(user.lastName)) return false; | |
| return true; | |
| } | |
| @Override | |
| public int hashCode() { | |
| int result = id.hashCode(); | |
| result = 31 * result + firstName.hashCode(); | |
| result = 31 * result + lastName.hashCode(); | |
| result = 31 * result + email.hashCode(); | |
| return result; | |
| } | |
| @Override | |
| public String toString() { | |
| return "User{" + | |
| "id='" + id + '\'' + | |
| ", firstName='" + firstName + '\'' + | |
| ", lastName='" + lastName + '\'' + | |
| ", email='" + email + '\'' + | |
| '}'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment