Merge pull request #9700 from sampada07/JAVA-2107
JAVA-2107: Split or move spring-thymeleaf module
This commit is contained in:
commit
51276387dc
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Student Form</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Student Form</h1>
|
||||
<form action="#" th:action="@{/saveStudent}" th:object="${student}"
|
||||
method="post">
|
||||
<ul>
|
||||
<li th:errors="*{id}" />
|
||||
<li th:errors="*{name}" />
|
||||
<li th:errors="*{gender}" />
|
||||
<li th:errors="*{percentage}" />
|
||||
</ul>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<td><label th:text="ID" /></td>
|
||||
<td><input type="number" th:field="*{id}" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label th:text="Name" /></td>
|
||||
<td><input type="text" th:field="*{name}" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label th:text="Gender" /></td>
|
||||
<td><select th:field="*{gender}">
|
||||
<option th:value="'M'" th:text="Male"></option>
|
||||
<option th:value="'F'" th:text="Female"></option>
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label th:text="Percentage" /></td>
|
||||
<td><select id="percentage" name="percentage">
|
||||
<option th:each="i : ${#numbers.sequence(0, 100)}" th:value="${i}" th:text="${i}" th:selected="${i==75}"></option>
|
||||
</select></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user