Fakultas Ilmu Komputer UI
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tutorial 0 Adpro
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ridjky Tegar Perkasa - 2006525330
Tutorial 0 Adpro
Merge requests
!1
Implement student page
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Implement student page
task-implementation-student
into
master
Overview
0
Commits
1
Pipelines
0
Changes
8
Merged
Ridjky Tegar Perkasa - 2006525330
requested to merge
task-implementation-student
into
master
3 years ago
Overview
0
Commits
1
Pipelines
0
Changes
8
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
b5c931b2
1 commit,
3 years ago
8 files
+
213
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
src/main/java/id/ac/ui/cs/advprog/tutorial0/controller/StudentController.java
0 → 100644
+
47
−
0
Options
package
id.ac.ui.cs.advprog.tutorial0.controller
;
import
id.ac.ui.cs.advprog.tutorial0.exception.DuplicateStudentNameException
;
import
id.ac.ui.cs.advprog.tutorial0.model.Student
;
import
id.ac.ui.cs.advprog.tutorial0.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.GetMapping
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
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"
;
}
}
Loading