<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" xmlns:th="http://www.thymeleaf.org">
<title>Index page</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html><!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Электронный деканат</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample05"
aria-controls="navbarsExample05" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExample05">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Главная</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Студенты <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Группы</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Кафедры</a>
</li>
</ul>
<form class="form-inline mt-2 mt-md-0">
<input class="form-control mr-sm-2" type="text" placeholder="Введите текст" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Поиск</button>
</form>
</div>
</nav>
<div class="container">
<div class="py-5 text-center">
<h2>Управление студентами</h2>
<p class="lead">На данной странице вы можете добавить, отредактировать поля или удалить студентов кафедры</p>
</div>
<div class="row">
<div class="col">
<h2>Группа АИ-171</h2>
</div>
<div class="col col-lg-3">
<a th:href="@{~/add_student}" class="btn btn-lg btn-block btn-outline-primary" role="button"
aria-disabled="true">Добавить студента</a>
</div>
</div>
<br/>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th class="text-justify">#</th>
<th class="text-justify">Фамилия</th>
<th class="text-justify">Имя</th>
<th class="text-justify">Отчество</th>
<th class="text-justify">Почта</th>
<th class="text-justify">Телефон</th>
<th class="text-justify">Адрес</th>
</tr>
</thead>
<tbody>
<tr th:each="student : ${students}">
<td class="align-middle"><span th:text="${student.id}"/></td>
<td class="align-middle"><span th:text="${student.lastName}"/></td>
<td class="align-middle"><span th:text="${student.firstName}"/></td>
<td class="align-middle"><span th:text="${student.patronymic}"/></td>
<td class="align-middle"><span th:text="${student.email}"/></td>
<td class="align-middle"><span th:text="${student.phone}"/></td>
<td class="align-middle"><span th:text="${student.address}"/></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html><!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Добавление студента</title>
</head>
<body class="bg-light">
<div class="container">
<div class="py-5 text-center">
<h2>Добавление студента</h2>
<p class="lead">Заполните поля и нажмите кнопку 'Добавить студента'</p>
</div>
<form method="post" class="needs-validation" novalidate>
<div class="row">
<div class="col-md-12">
<h4 class="mb-3">Поля для заполнения</h4>
<div class="row">
<div class="col-md-4 mb-3">
<label for="lastName">Фамилия</label>
<input type="text" class="form-control" id="lastName" placeholder=""
value="" required>
</div>
<div class="col-md-4 mb-3">
<label for="firstName">Имя</label>
<input type="text" class="form-control" id="firstName" placeholder=""
value="" required>
</div>
<div class="col-md-4 mb-3">
<label for="patronymic">Отчество</label>
<input type="text" class="form-control" id="patronymic" placeholder=""
value="" required>
</div>
</div>
<div class="mb-3">
<label for="email">Электронная почта</label>
<input type="email" class="form-control" id="email"
placeholder="" value="" required>
</div>
<div class="mb-3">
<label for="phone">Телефон</label>
<input type="text" class="form-control" id="phone"
placeholder="(ХХХ) ХХХ-ХХХХ" value="" required>
</div>
<div class="mb-3">
<label for="address">Домашний адрес</label>
<input type="text" class="form-control" id="address" placeholder="" value=""
required>
</div>
<hr class="mb-4">
<button class="btn btn-primary btn-lg btn-block" type="submit" value="Submit">Добавить студента</button>
</form>
</div>
</div>
</div>
<br/><br/><br/>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>@Controller
public class StudentController {
@GetMapping("/")
public String index(Model model) {
return "index";
}
@GetMapping("/add_student")
public String addStudent(Model model) {
return "add_student";
}
} <div class="col col-lg-3">
<a th:href="@{~/add_student}" class="btn btn-lg btn-block btn-outline-primary" role="button"
aria-disabled="true">Добавить студента</a>
</div>public class Student {
private long id;
private String lastName;
private String firstName;
private String patronymic;
private String email;
private String phone;
private String address;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getPatronymic() {
return patronymic;
}
public void setPatronymic(String patronymic) {
this.patronymic = patronymic;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Student() {}
public Student(String lastName, String firstName, String patronymic, String email, String phone, String address) {
this.lastName = lastName;
this.firstName = firstName;
this.patronymic = patronymic;
this.email = email;
this.phone = phone;
this.address = address;
}
}@Controller
public class StudentController {
...
@GetMapping("/add_student")
public String addStudent(Model model) {
model.addAttribute("student", new Student());
return "add_student";
}
}<form enctype="multipart/form-data" action="#" th:action="@{/add_student}" th:object="${student}" method="post" class="needs-validation"
novalidate>
<div class="row">
<div class="col-md-12">
<h4 class="mb-3">Поля для заполнения</h4>
<div class="row">
<div class="col-md-4 mb-3">
<label for="lastName">Фамилия</label>
<input th:field="*{lastName}" type="text" class="form-control" id="lastName" placeholder=""
value="" required>
</div>
<div class="col-md-4 mb-3">
<label for="firstName">Имя</label>
<input th:field="*{firstName}" type="text" class="form-control" id="firstName" placeholder=""
value="" required>
</div>
<div class="col-md-4 mb-3">
<label for="patronymic">Отчество</label>
<input th:field="*{patronymic}" type="text" class="form-control" id="patronymic" placeholder=""
value="" required>
</div>
</div>
<div class="mb-3">
<label for="email">Электронная почта</label>
<input th:field="*{email}" type="email" class="form-control" id="email"
placeholder="" value="" required>
</div>
<div class="mb-3">
<label for="phone">Телефон</label>
<input th:field="*{phone}" type="text" class="form-control" id="phone"
placeholder="(ХХХ) ХХХ-ХХХХ" value="" required>
</div>
<div class="mb-3">
<label for="address">Домашний адрес</label>
<input th:field="*{address}" type="text" class="form-control" id="address" placeholder="" value=""
required>
</div>
<hr class="mb-4">
<button class="btn btn-primary btn-lg btn-block" type="submit" value="Submit">Добавить студента</button>
</div>
</div>
</form>@Controller
public class StudentController {
...
@PostMapping("/add_student")
public String greetingSubmit(@ModelAttribute Student student) {
return "redirect:/";
}
}@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue
private long id;
private String lastName;
private String firstName;
private String patronymic;
private String email;
private String phone;
private String address;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getPatronymic() {
return patronymic;
}
public void setPatronymic(String patronymic) {
this.patronymic = patronymic;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Student() {
}
public Student(String lastName, String firstName, String patronymic, String email, String phone, String address) {
this.lastName = lastName;
this.firstName = firstName;
this.patronymic = patronymic;
this.email = email;
this.phone = phone;
this.address = address;
}
}public interface StudentRepository extends JpaRepository<Student,Long> {}@Service
public class StudentService {
private StudentRepository repository;
@Autowired
public void setRepository(StudentRepository repository) {
this.repository = repository;
}
public void saveStudent(Student student) {
repository.save(student);
}
}@Controller
public class StudentController {
private StudentService service;
@Autowired
public void setService(StudentService service) {
this.service = service;
}
...
@PostMapping("/add_student")
public String greetingSubmit(@ModelAttribute Student student) {
service.saveStudent(student);
return "redirect:/";
}
}@Controller
public class StudentController {
private StudentService service;
@Autowired
public void setService(StudentService service) {
this.service = service;
}
@GetMapping("/")
public String index(Model model) {
model.addAttribute("students", service.getAllStudents());
return "index";
}
...
}<table class="table table-striped">
<thead>
<tr>
<th class="text-justify">#</th>
<th class="text-justify">Фамилия</th>
<th class="text-justify">Имя</th>
<th class="text-justify">Отчество</th>
<th class="text-justify">Почта</th>
<th class="text-justify">Телефон</th>
<th class="text-justify">Адрес</th>
</tr>
</thead>
<tbody>
<tr th:each="student : ${students}">
<td class="align-middle"><span th:text="${student.id}"/></td>
<td class="align-middle"><span th:text="${student.lastName}"/></td>
<td class="align-middle"><span th:text="${student.firstName}"/></td>
<td class="align-middle"><span th:text="${student.patronymic}"/></td>
<td class="align-middle"><span th:text="${student.email}"/></td>
<td class="align-middle"><span th:text="${student.phone}"/></td>
<td class="align-middle"><span th:text="${student.address}"/></td>
</tr>
</tbody>
</table><form enctype="multipart/form-data" action="#" th:action="@{/}" th:object="${student}" method="post" class="needs-validation">
<div class="row">
<div class="col-md-12">
<h4 class="mb-3">Поля для заполнения</h4>
<div class="row">
<div class="col-md-6 mb-3">
<label for="lastName">Фамилия</label>
<input th:field="*{lastName}" type="text" class="form-control" id="lastName">
</div>
<div class="col-md-6 mb-3">
<label for="firstName">Имя</label>
<input th:field="*{firstName}" type="text" class="form-control" id="firstName">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="email">Электронная почта</label>
<input th:field="*{email}" type="text" class="form-control" id="email">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="age">Возраст</label>
<input th:field="*{age}" type="number" class="form-control" id="age">
</div>
</div>
<hr class="mb-4">
<button class="btn btn-primary btn-lg btn-block" type="submit" value="Submit">Добавить студента</button>
</div>
</div>
</form><?xml version="1.0" encoding="UTF-8"?>
<project ...>
...
<dependencies>
...
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
</dependencies>
...
</project>public class Student {
// Имя должно быть длиной от 2 до 50 символов
@Size(min = 2, max= 50, message = "First name should be from 2 to 50 characters")
private String firstName;
// Фамилия должна быть длиной от 2 до 50 символов
@Size(min = 2, max= 50, message = "Last name should be from 2 to 50 characters")
private String lastName;
// Возраст должен быть целым числом от 13 до 65
@Range(min = 13, max = 65, message = "Student age should be from 13 to 65 years")
private int age;
// Для валидации электронной почты используем регулярное выражение
@Pattern(regexp = "^[\\\\w!#$%&’*+/=?`{|}~^-]+(?:\\\\.[\\\\w!#$%&’*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\\\.)+[a-zA-Z]{2,6}$",
message = "Invalid email format")
private String email;
...
} @GetMapping("/")
public String addStudent(Model model) {
model.addAttribute("student", new Student());
return "index";
}
@PostMapping("/")
public String processAddStudentForm(@Valid Student student, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
System.out.println("Validation has been failed!");
return "index";
}
System.out.println(student);
list.add(student);
return "redirect:/";
}<div class="col-md-6 mb-3">
<label for="lastName">Фамилия</label>
<input th:field="*{lastName}" type="text" class="form-control" id="lastName">
<small class="text-danger" th:if="${#fields.hasErrors('lastName')}" th:errors="*{lastName}"/>
</div><!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Добавление студента</title>
</head>
<body class="bg-light">
<div class="container">
<div class="py-5 text-center">
<h2>Добавление студента</h2>
<p class="lead">Заполните поля и нажмите кнопку 'Добавить студента'</p>
</div>
<form enctype="multipart/form-data" action="#" th:action="@{/}" th:object="${student}" method="post">
<div class="row">
<div class="col-md-12">
<h4 class="mb-3">Поля для заполнения</h4>
<div class="row">
<div class="col-md-6 mb-3">
<label for="lastName">Фамилия</label>
<input th:field="*{lastName}" type="text" class="form-control" id="lastName">
<small class="text-danger" th:if="${#fields.hasErrors('lastName')}" th:errors="*{lastName}"/>
</div>
<div class="col-md-6 mb-3">
<label for="firstName">Имя</label>
<input th:field="*{firstName}" type="text" class="form-control" id="firstName">
<small class="text-danger" th:if="${#fields.hasErrors('firstName')}" th:errors="*{firstName}"/>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="email">Электронная почта</label>
<input th:field="*{email}" type="text" class="form-control" id="email">
<small class="text-danger" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"/>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="age">Возраст</label>
<input th:value="${student.age > 0} ? ${student.age} : ''" th:field="*{age}" type="number" class="form-control" id="age">
<small class="text-danger" th:if="${#fields.hasErrors('age')}" th:errors="*{age}"/>
</div>
</div>
<hr class="mb-4">
<button class="btn btn-primary btn-lg btn-block" type="submit" value="Submit">Добавить студента</button>
</div>
</div>
</form>
</div>
</div>
</div>
<br/><br/><br/>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>public class Student {
// Имя должно быть длиной от 2 до 50 символов
@Size(min = 2, max= 50, message = "First name should be from 2 to 50 characters")
private String firstName;
// Фамилия должна быть длиной от 2 до 50 символов
@Size(min = 2, max= 50, message = "Last name should be from 2 to 50 characters")
private String lastName;
// Возраст должен быть целым числом от 13 до 65
@Range(min = 13, max = 65, message = "Student age should be from 13 to 65 years")
private int age;
// Для валидации электронной почты используем регулярное выражение
@Pattern(regexp = "^[a-zA-Z0-9_!#$%&’*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$",
message = "Invalid email format")
private String email;
public Student(String firstName, String lastName, int age, String email) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.email = email;
}
public Student() {
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}@Controller
public class StudentController {
private List<Student> list = new ArrayList<>();
@GetMapping("/")
public String addStudent(Model model) {
model.addAttribute("student", new Student());
return "index";
}
@PostMapping("/")
public String processAddStudentForm(@Valid Student student, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return "index";
}
System.out.println(student);
list.add(student);
return "redirect:/";
}
}<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Добавление студента</title>
</head>
<body class="bg-light">
<div class="container">
<div class="py-5 text-center">
<h2>Добавление студента</h2>
<p class="lead">Заполните поля и нажмите кнопку 'Добавить студента'</p>
</div>
<form enctype="multipart/form-data" action="#" th:action="@{/}" th:object="${student}" method="post">
<div class="row">
<div class="col-md-12">
<h4 class="mb-3">Поля для заполнения</h4>
<div class="row">
<div class="col-md-6 mb-3">
<label for="lastName">Фамилия</label>
<input th:field="*{lastName}" type="text" class="form-control" id="lastName">
<small class="text-danger" th:if="${#fields.hasErrors('lastName')}" th:errors="*{lastName}"/>
</div>
<div class="col-md-6 mb-3">
<label for="firstName">Имя</label>
<input th:field="*{firstName}" type="text" class="form-control" id="firstName">
<small class="text-danger" th:if="${#fields.hasErrors('firstName')}" th:errors="*{firstName}"/>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="email">Электронная почта</label>
<input th:field="*{email}" type="text" class="form-control" id="email">
<small class="text-danger" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"/>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="age">Возраст</label>
<input th:value="${student.age > 0} ? ${student.age} : ''" th:field="*{age}" type="number" class="form-control" id="age">
<small class="text-danger" th:if="${#fields.hasErrors('age')}" th:errors="*{age}"/>
</div>
</div>
<div class="form-group">
<label for="file">Choose file:</label>
<input type="file" name="file" class="form-control-file" id="file">
</div>
<hr class="mb-4">
<button class="btn btn-primary btn-lg btn-block" type="submit" value="Submit">Добавить студента</button>
</div>
</div>
</form>
</div>
</div>
</div>
<br/><br/><br/>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>@Controller
public class StudentController {
private List<Student> list = new ArrayList<>();
@GetMapping("/")
public String addStudent(Model model) {
model.addAttribute("student", new Student());
return "index";
}
@PostMapping("/")
public String processAddStudentForm(@Valid Student student, @RequestParam("file") MultipartFile file, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return "index";
}
System.out.println(student);
list.add(student);
// normalize the file path
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
// save the file on the local file system
try {
Path path = Paths.get("c:\\temp\\" + fileName);
Files.copy(file.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:/";
}
}spring.servlet.multipart.max-file-size=128KB
spring.servlet.multipart.max-request-size=128KB
spring.servlet.multipart.enabled=true <dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>











