diff --git a/spring-thymeleaf-3/README.md b/spring-thymeleaf-3/README.md index de18771c1e..66e64e7094 100644 --- a/spring-thymeleaf-3/README.md +++ b/spring-thymeleaf-3/README.md @@ -5,3 +5,4 @@ This module contains articles about Spring with Thymeleaf ## Relevant Articles: - [Add CSS and JS to Thymeleaf](https://www.baeldung.com/spring-thymeleaf-css-js) - [Formatting Currencies in Spring Using Thymeleaf](https://www.baeldung.com/spring-thymeleaf-currencies) +- [Working with Select and Option in Thymeleaf](https://www.baeldung.com/thymeleaf-select-option) diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java new file mode 100644 index 0000000000..3bb6576096 --- /dev/null +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java @@ -0,0 +1,60 @@ +package com.baeldung.thymeleaf.option; + +import java.io.Serializable; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +/** + * + * Simple student POJO with few fields + * + */ +public class Student implements Serializable { + + private static final long serialVersionUID = -8582553475226281591L; + + @NotNull(message = "Student ID is required.") + @Min(value = 1000, message = "Student ID must be at least 4 digits.") + private Integer id; + + @NotNull(message = "Student name is required.") + private String name; + + @NotNull(message = "Student gender is required.") + private Character gender; + + private Float percentage; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Character getGender() { + return gender; + } + + public void setGender(Character gender) { + this.gender = gender; + } + + public Float getPercentage() { + return percentage; + } + + public void setPercentage(Float percentage) { + this.percentage = percentage; + } +} diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java new file mode 100644 index 0000000000..ac75c8ff3a --- /dev/null +++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java @@ -0,0 +1,24 @@ +package com.baeldung.thymeleaf.option; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + + +/** + * Handles requests for the student model. + * + */ +@Controller +public class StudentController { + + + @RequestMapping(value = "/student", method = RequestMethod.GET) + public String addStudent(Model model) { + model.addAttribute("student", new Student()); + return "option/studentForm.html"; + } + + +} diff --git a/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html b/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html new file mode 100644 index 0000000000..050ac55fc1 --- /dev/null +++ b/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html @@ -0,0 +1,42 @@ + + + +Student Form + + +

Student Form

+
+ + + + + + + + + + + + + + + + + + +
+
+ + diff --git a/spring-thymeleaf/README.md b/spring-thymeleaf/README.md index a5c6791609..7c3d4cafa3 100644 --- a/spring-thymeleaf/README.md +++ b/spring-thymeleaf/README.md @@ -13,7 +13,6 @@ This module contains articles about Spring with Thymeleaf - [Conditionals in Thymeleaf](https://www.baeldung.com/spring-thymeleaf-conditionals) - [Iteration in Thymeleaf](https://www.baeldung.com/thymeleaf-iteration) - [Spring with Thymeleaf Pagination for a List](https://www.baeldung.com/spring-thymeleaf-pagination) -- [Working with Select and Option in Thymeleaf](https://www.baeldung.com/thymeleaf-select-option) - [[next -->]](/spring-thymeleaf-2) ### Build the Project