Fakultas Ilmu Komputer UI

Commit aed6e92d authored by M. Margaretha Stella's avatar M. Margaretha Stella
Browse files

Implement student page

parent bb9f815e
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;
public class StudentController {
private StudentService service;
public String studentListPage(Model model) {
List<Student> allStudents = service.findAll();
model.addAttribute("students", allStudents);
return "studentList";
public String createStudentPage(Model model) {
Student student = new Student();
model.addAttribute("student", student);
return "createStudent";
public String createStudentPost(@ModelAttribute Student student, Model model) {
try {
} catch (DuplicateStudentNameException e) {
model.addAttribute("error", e);
model.addAttribute("student", student);
return "createStudent";
return "redirect:list";
\ No newline at end of file
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
package id.ac.ui.cs.advprog.turorial0.model;
import lombok.Getter;
import lombok.Setter;
public class Student {
private String name;
private String npm;
private String address;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment