Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

39.4. Record 作为 Service

		
@Service
public record PersonService(PersonRepository personRepository){

  	//保存person
    public Person save(Person person){
        Person person = new Person(person.firstName(), person.lastName(), person.age());
        return personRepository.save(person);
    }
  
 	//按照lastName查询people,返回值只有firstName和lastName
    public List<PersonOnlyWithName> findByLastName(String lastName){
        return personRepository.findByLastName(lastName);
    }
}		
		
		
		
public interface PersonRepository extends JpaRepository<Person, Long> {
    List<PersonOnlyWithName> findByLastName(String lastName);
}