Created
February 10, 2014 22:58
-
-
Save jbrackett/8925943 to your computer and use it in GitHub Desktop.
Repository and Domain for spring-data-jpa tutorial
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 com.example.domain; | |
import java.io.Serializable; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.Id; | |
import javax.persistence.Table; | |
@Entity | |
@Table | |
public class Person implements Serializable { | |
private static final long serialVersionUID = 1L; | |
@Id | |
@GeneratedValue | |
private Long id; | |
private String firstName; | |
private String lastName; | |
public Person() { | |
} | |
public Person(String firstName, String lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
public Long getId() { | |
return id; | |
} | |
public void setId(Long 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; | |
} | |
@Override | |
public int hashCode() { | |
final int prime = 31; | |
int result = 1; | |
result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); | |
result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); | |
return result; | |
} | |
@Override | |
public boolean equals(Object obj) { | |
if (this == obj) | |
return true; | |
if (obj == null) | |
return false; | |
if (getClass() != obj.getClass()) | |
return false; | |
Person other = (Person) obj; | |
if (firstName == null) { | |
if (other.firstName != null) | |
return false; | |
} | |
else if (!firstName.equals(other.firstName)) | |
return false; | |
if (lastName == null) { | |
if (other.lastName != null) | |
return false; | |
} | |
else if (!lastName.equals(other.lastName)) | |
return false; | |
return true; | |
} | |
} |
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 com.example.repositories; | |
import java.util.List; | |
import org.springframework.data.repository.CrudRepository; | |
import com.example.domain.Person; | |
public interface PersonRepository extends CrudRepository<Person, Long> { | |
List<Person> findByFirstName(String firstName); | |
List<Person> findByLastName(String lastName); | |
List<Person> findByLastNameContaining(String partialLastName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment