File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
java/com/gdsc/springbootworkshop Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 5
5
import org .springframework .beans .factory .annotation .Autowired ;
6
6
import org .springframework .web .bind .annotation .*;
7
7
8
+ import javax .websocket .server .PathParam ;
8
9
import java .util .List ;
9
10
10
11
@ RestController
@@ -24,6 +25,24 @@ Student addStudent(@RequestBody Student student) throws Exception {
24
25
return studentService .addStudent (student );
25
26
}
26
27
28
+ @ PutMapping ("/{id}" )
29
+ Student updateStudent (@ PathVariable ("id" ) Long id , @ RequestBody Student student ){
30
+ return studentService .updateStudent (id , student );
31
+ }
32
+
33
+ @ DeleteMapping ("/{id}" )
34
+ void deleteStudent (@ PathVariable ("id" ) Long id ){
35
+ studentService .deleteStudent (id );
36
+ }
37
+
38
+ @ GetMapping ("/{id}" )
39
+ Student findById (@ PathVariable ("id" ) Long id ){
40
+ return studentService .findById (id );
41
+ }
42
+
43
+
44
+
45
+
27
46
28
47
29
48
}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ public Student addStudent(Student student) throws Exception {
27
27
28
28
@ Override
29
29
public Student updateStudent (Long id , Student student ) {
30
- if (studentRepository .findById (id ).isPresent () ){
30
+ if (studentRepository .findById (id ).isPresent ()){
31
31
Student toUpdateStudent = studentRepository .findById (id ).get ();
32
32
toUpdateStudent .setFirstName (student .getFirstName ());
33
33
toUpdateStudent .setLastName (student .getLastName ());
Original file line number Diff line number Diff line change @@ -9,4 +9,4 @@ spring.datasource.password=
9
9
# # JPA / HIBERNATE ###
10
10
spring.jpa.show-sql =true
11
11
spring.jpa.generate-ddl =true
12
- spring.jpa.hibernate.ddl-auto =create
12
+ spring.jpa.hibernate.ddl-auto =update
You can’t perform that action at this time.
0 commit comments