Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
M MARGARETHA STELLA KALYANADUHITA T
Tutorial 0 AdvProg
Commits
aed6e92d
Commit
aed6e92d
authored
Feb 13, 2022
by
M. Margaretha Stella
Browse files
Implement student page
parent
bb9f815e
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/id/ac/ui/cs/advprog/turorial0/controller/StudentController.java
0 → 100644
View file @
aed6e92d
package
id.ac.ui.cs.advprog.turorial0.controller
;
import
id.ac.ui.cs.advprog.turorial0.exception.DuplicateStudentNameException
;
import
id.ac.ui.cs.advprog.turorial0.model.Student
;
import
id.ac.ui.cs.advprog.turorial0.service.StudentService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@Controller
@RequestMapping
(
"/student"
)
public
class
StudentController
{
@Autowired
private
StudentService
service
;
@GetMapping
(
"/list"
)
public
String
studentListPage
(
Model
model
)
{
List
<
Student
>
allStudents
=
service
.
findAll
();
model
.
addAttribute
(
"students"
,
allStudents
);
return
"studentList"
;
}
@GetMapping
(
"/create"
)
public
String
createStudentPage
(
Model
model
)
{
Student
student
=
new
Student
();
model
.
addAttribute
(
"student"
,
student
);
return
"createStudent"
;
}
@PostMapping
(
"/create"
)
public
String
createStudentPost
(
@ModelAttribute
Student
student
,
Model
model
)
{
try
{
service
.
create
(
student
);
}
catch
(
DuplicateStudentNameException
e
)
{
model
.
addAttribute
(
"error"
,
e
);
model
.
addAttribute
(
"student"
,
student
);
return
"createStudent"
;
}
return
"redirect:list"
;
}
}
\ No newline at end of file
src/main/java/id/ac/ui/cs/advprog/turorial0/exception/DuplicateStudentNameException.java
0 → 100644
View file @
aed6e92d
package
id.ac.ui.cs.advprog.turorial0.exception
;
public
class
DuplicateStudentNameException
extends
RuntimeException
{
public
DuplicateStudentNameException
(
String
studentName
)
{
super
(
String
.
format
(
"The student name %s is a duplicate!"
,
studentName
));
}
}
\ No newline at end of file
src/main/java/id/ac/ui/cs/advprog/turorial0/model/Student.java
0 → 100644
View file @
aed6e92d
package
id.ac.ui.cs.advprog.turorial0.model
;
import
lombok.Getter
;
import
lombok.Setter
;
@Getter
@Setter
public
class
Student
{
private
String
name
;
private
String
npm
;
private
String
address
;
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment