CrudRepository接口

CrudRepository

  • CrudRepository接口提供乐儿最基本的对实体类的增、删、改、查操作

    CrudRepository接口_第1张图片

  • 测试保存 只需继承相应的接口 ,然后在service层中定义即可

@Service
public class PersonService {
    @Autowired
    private PersonRepsotory person;

    public void savePersons(List persons) {
        person.save(persons);
    }


}


@Test
   public void crudRepsotoryTest(){
       List persons = new ArrayList<>();
       for(int i = 'a';i<'z';i++){
           Person p = new  Person();
           p.setBrith(new Date());
           p.setEmail((char)i+""+(char)i+"@guigu.com");
           p.setName((char)i+""+(char)i);
           persons.add(p);
       }
       personService.savePersons(persons);
   }

你可能感兴趣的:(SpringData)