Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
FOSS_Final_Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
박준우
FOSS_Final_Server
Commits
8f5b80f7
Commit
8f5b80f7
authored
2 years ago
by
박준우
Browse files
Options
Downloads
Patches
Plain Diff
refactor: change RestController to controller
parent
f5fa3a5b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/guide/server/StudentController.java
+19
-13
19 additions, 13 deletions
src/main/java/com/guide/server/StudentController.java
with
19 additions
and
13 deletions
src/main/java/com/guide/server/StudentController.java
+
19
−
13
View file @
8f5b80f7
package
com.guide.server
;
package
com.guide.server
;
import
org.springframework.beans.factory.annotation.Autowired
;
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
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
@
Rest
Controller
@Controller
public
class
StudentController
{
public
class
StudentController
{
private
final
StudentService
studentService
;
private
final
StudentService
studentService
;
...
@@ -16,45 +19,48 @@ public class StudentController {
...
@@ -16,45 +19,48 @@ public class StudentController {
}
}
@PostMapping
(
"/student/add"
)
@PostMapping
(
"/student/add"
)
public
String
createStudent
(
public
ResponseEntity
<?>
createStudent
(
@RequestParam
String
name
,
@RequestParam
String
name
,
@RequestParam
String
stdId
,
@RequestParam
String
stdId
,
@RequestParam
Integer
grade
,
@RequestParam
Integer
grade
,
@RequestParam
String
major
)
{
@RequestParam
String
major
)
{
System
.
out
.
println
(
"실행중1"
);
studentService
.
saveStudent
(
Student
.
builder
().
name
(
name
).
stdId
(
stdId
).
grade
(
grade
).
major
(
major
).
build
());
studentService
.
saveStudent
(
Student
.
builder
().
name
(
name
).
stdId
(
stdId
).
grade
(
grade
).
major
(
major
).
build
());
return
"success"
;
return
new
ResponseEntity
<>(
"success"
,
HttpStatus
.
OK
)
;
}
}
@PutMapping
(
"/student/update"
)
@PutMapping
(
"/student/update"
)
public
String
updateStudent
(
public
ResponseEntity
<?>
updateStudent
(
@RequestParam
Long
id
,
@RequestParam
Long
id
,
@RequestParam
String
major
)
{
@RequestParam
String
major
)
{
System
.
out
.
println
(
"실행중3"
);
Optional
<
Student
>
student
=
studentService
.
findOne
(
id
);
Optional
<
Student
>
student
=
studentService
.
findOne
(
id
);
if
(
student
.
isPresent
()){
if
(
student
.
isPresent
()){
Student
newStudent
=
student
.
get
();
Student
newStudent
=
student
.
get
();
newStudent
.
setMajor
(
major
);
newStudent
.
setMajor
(
major
);
studentService
.
saveStudent
(
newStudent
);
studentService
.
saveStudent
(
newStudent
);
return
"success"
;
return
new
ResponseEntity
<>(
"success"
,
HttpStatus
.
OK
)
;
}
}
return
"fail"
;
return
new
ResponseEntity
<>(
"fail"
,
HttpStatus
.
OK
)
;
}
}
@GetMapping
(
"/student/stdId"
)
@GetMapping
(
"/student/stdId"
)
public
Student
getStudentByStdId
(
@RequestParam
String
stdId
){
public
ResponseEntity
<?>
getStudentByStdId
(
@RequestParam
String
stdId
){
return
studentService
.
findOne
(
stdId
).
orElse
(
null
);
return
new
ResponseEntity
<>(
studentService
.
findOne
(
stdId
).
orElse
(
null
)
,
HttpStatus
.
OK
)
;
}
}
@GetMapping
(
"/student/list"
)
@GetMapping
(
"/student/list"
)
public
List
<
Student
>
getStudentList
(){
public
ResponseEntity
<?>
getStudentList
(){
return
studentService
.
findStudents
();
System
.
out
.
println
(
"실행중2"
);
return
new
ResponseEntity
<>(
studentService
.
findStudents
(),
HttpStatus
.
OK
);
}
}
@DeleteMapping
(
"/student/delete"
)
@DeleteMapping
(
"/student/delete"
)
public
String
deleteStudent
(
@RequestParam
Long
id
){
public
ResponseEntity
<?>
deleteStudent
(
@RequestParam
Long
id
){
Optional
<
Student
>
student
=
studentService
.
findOne
(
id
);
Optional
<
Student
>
student
=
studentService
.
findOne
(
id
);
if
(
student
.
isPresent
()){
if
(
student
.
isPresent
()){
studentService
.
deleteStudent
(
id
);
studentService
.
deleteStudent
(
id
);
return
"success"
;
return
new
ResponseEntity
<>(
"success"
,
HttpStatus
.
OK
)
;
}
}
return
"fail"
;
return
new
ResponseEntity
<>(
"fail"
,
HttpStatus
.
OK
)
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment