Skip to content
Snippets Groups Projects
Commit 8f5b80f7 authored by 박준우's avatar 박준우
Browse files

refactor: change RestController to controller

parent f5fa3a5b
No related branches found
No related tags found
No related merge requests found
package com.guide.server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@Controller
public class StudentController {
private final StudentService studentService;
......@@ -16,45 +19,48 @@ public class StudentController {
}
@PostMapping("/student/add")
public String createStudent(
public ResponseEntity<?> createStudent(
@RequestParam String name,
@RequestParam String stdId,
@RequestParam Integer grade,
@RequestParam String major) {
System.out.println("실행중1");
studentService.saveStudent(Student.builder().name(name).stdId(stdId).grade(grade).major(major).build());
return "success";
return new ResponseEntity<>("success", HttpStatus.OK);
}
@PutMapping("/student/update")
public String updateStudent(
public ResponseEntity<?> updateStudent(
@RequestParam Long id,
@RequestParam String major) {
System.out.println("실행중3");
Optional<Student> student = studentService.findOne(id);
if(student.isPresent()){
Student newStudent = student.get();
newStudent.setMajor(major);
studentService.saveStudent(newStudent);
return "success";
return new ResponseEntity<>("success", HttpStatus.OK);
}
return "fail";
return new ResponseEntity<>("fail", HttpStatus.OK);
}
@GetMapping("/student/stdId")
public Student getStudentByStdId(@RequestParam String stdId){
return studentService.findOne(stdId).orElse(null);
public ResponseEntity<?> getStudentByStdId(@RequestParam String stdId){
return new ResponseEntity<>(studentService.findOne(stdId).orElse(null), HttpStatus.OK);
}
@GetMapping("/student/list")
public List<Student> getStudentList(){
return studentService.findStudents();
public ResponseEntity<?> getStudentList(){
System.out.println("실행중2");
return new ResponseEntity<>(studentService.findStudents(), HttpStatus.OK);
}
@DeleteMapping("/student/delete")
public String deleteStudent(@RequestParam Long id){
public ResponseEntity<?> deleteStudent(@RequestParam Long id){
Optional<Student> student = studentService.findOne(id);
if(student.isPresent()){
studentService.deleteStudent(id);
return "success";
return new ResponseEntity<>("success", HttpStatus.OK);
}
return "fail";
return new ResponseEntity<>("fail", HttpStatus.OK);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment