-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathPersonService.java
More file actions
49 lines (40 loc) · 1.13 KB
/
PersonService.java
File metadata and controls
49 lines (40 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package io.zipcoder.crudapp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class PersonService {
@Autowired
private PersonRepository repository;
public Person create(Person person){
return repository.save(person);
}
public Person read(Long id){
return repository.findOne(id);
}
public Iterable<Person> readAll(){
// Iterable<Person> personIterable=repository.findAll();
// List<Person> result=new ArrayList<>();
// personIterable.forEach(result::add);
// return result;
return repository.findAll();
}
public Person update(Long id,Person newData) {
Person newP = read(id);
newP.setFirstName(newData.getFirstName());
newP.setLastName(newData.getLastName());
repository.save(newP);
return newP;
// Person newP=read(id);
//newData.setLastName(newP.getLastName());
//repository.save(newData);
}
public Person delete(Person person){
repository.delete(person);
return person;
}
public Person delete(Long id){
return delete(read(id));
}
}