-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControllerStudent.java
63 lines (44 loc) · 1.36 KB
/
ControllerStudent.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.spring.Controller;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.example.Repository.StudentRepository;
import com.example.dto.Student;
@RestController
public class ControllerStudent {
@Autowired
StudentRepository sr;
@PostMapping("/addStud")
public String addStudent(@RequestBody Student s) {
sr.save(s);
return "Student Added";
}
@GetMapping("fetchStud")
public Student fetchStudent(@RequestParam int id) {
Optional<Student> o = sr.findById(id);
Student s1=o.get();
return s1;
}
@PutMapping("/upstud")
public String updateStudent(@RequestBody Student sty) {
sr.save(sty);
return "Updated";
}
@DeleteMapping("/delstud")
public String delStudent(@RequestParam int id) {
sr.deleteById(id);
return "deleted";
}
@GetMapping("/allData")
public List<Student> findAll(){
List l=sr.findAll();
return l;
}
}