Minor changes

This commit is contained in:
gmaipady 2015-12-15 15:52:52 +05:30 committed by David Morley
parent 692d52c0da
commit 6a6c546c0c
7 changed files with 128 additions and 65 deletions

View File

@ -53,13 +53,18 @@ public class StudentController {
Student student1 = new Student(); Student student1 = new Student();
student1.setId(1001); student1.setId(1001);
student1.setName("John Smith"); student1.setName("John Smith");
student1.setGender('M');
student1.setPercentage(Float.valueOf("80.45"));
students.add(student1); students.add(student1);
Student student2 = new Student(); Student student2 = new Student();
student2.setId(1002); student2.setId(1002);
student2.setName("Jane Williams"); student2.setName("Jane Williams");
students.add(student2); student2.setGender('F');
student2.setPercentage(Float.valueOf("60.25"));
students.add(student2);
return students; return students;
} }
} }

View File

@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull;
/** /**
* *
* Simple student POJO with two fields - id and name * Simple student POJO with few fields
* *
*/ */
public class Student implements Serializable { public class Student implements Serializable {
@ -18,9 +18,14 @@ public class Student implements Serializable {
@Min(value = 1000, message = "Student ID must be atleast 4 digits.") @Min(value = 1000, message = "Student ID must be atleast 4 digits.")
private Integer id; private Integer id;
@NotNull(message = "Student Name is required.") @NotNull(message = "Student name is required.")
private String name; private String name;
@NotNull(message = "Student gender is required.")
private Character gender;
private Float percentage;
public Integer getId() { public Integer getId() {
return id; return id;
} }
@ -37,4 +42,19 @@ public class Student implements Serializable {
this.name = 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;
}
} }

View File

@ -1,4 +1,9 @@
msg.id=ID msg.id=ID
msg.name=Name msg.name=Name
msg.gender=Gender
msg.percent=Percentage
welcome.message=Welcome Student !!! welcome.message=Welcome Student !!!
msg.AddStudent=Add Student
msg.ListStudents=List Students
msg.Home=Home

View File

@ -26,7 +26,7 @@
<!-- Message source --> <!-- Message source -->
<beans:bean id="messageSource" <beans:bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"> class="org.springframework.context.support.ResourceBundleMessageSource">
<beans:property name="basename" value="messages"></beans:property> <beans:property name="basename" value="messages" />
</beans:bean> </beans:bean>
<!-- Resolves views selected for rendering by @Controllers to .html resources <!-- Resolves views selected for rendering by @Controllers to .html resources
@ -45,7 +45,7 @@
<beans:bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver"> <beans:bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<beans:property name="templateEngine" ref="templateEngine" /> <beans:property name="templateEngine" ref="templateEngine" />
<beans:property name="order" value="1" /> <beans:property name="order" value="1" />
<beans:property name="viewNames" value="*"></beans:property> <beans:property name="viewNames" value="*" />
</beans:bean> </beans:bean>
<context:component-scan base-package="org.baeldung.thymeleaf.controller" /> <context:component-scan base-package="org.baeldung.thymeleaf.controller" />

View File

@ -11,16 +11,29 @@
<ul> <ul>
<li th:errors="*{id}" /> <li th:errors="*{id}" />
<li th:errors="*{name}" /> <li th:errors="*{name}" />
<li th:errors="*{gender}" />
<li th:errors="*{percentage}" />
</ul> </ul>
<table border="1"> <table border="1">
<tr> <tr>
<td><label th:text="#{msg.id}"></label></td> <td><label th:text="#{msg.id}" /></td>
<td><input type="number" th:field="*{id}" /></td> <td><input type="number" th:field="*{id}" /></td>
</tr> </tr>
<tr> <tr>
<td><label th:text="#{msg.name}"></label></td> <td><label th:text="#{msg.name}" /></td>
<td><input type="text" th:field="*{name}" /></td> <td><input type="text" th:field="*{name}" /></td>
</tr> </tr>
<tr>
<td><label th:text="#{msg.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="#{msg.percent}" /></td>
<td><input type="text" th:field="*{percentage}" /></td>
</tr>
<tr> <tr>
<td><input type="submit" value="Submit" /></td> <td><input type="submit" value="Submit" /></td>
</tr> </tr>

View File

@ -6,10 +6,18 @@
</head> </head>
<body> <body>
<h1> <h1>
<span th:text="#{welcome.message}"></span> <span th:text="#{welcome.message}" />
</h1> </h1>
<P> <p>
Current time is <span th:text="${serverTime}"></span> Current time is <span th:text="${serverTime}" />
</P> </p>
<table>
<tr>
<td><a th:href="@{/addStudent}" th:text="#{msg.AddStudent}" /></td>
</tr>
<tr>
<td><a th:href="@{/listStudents}" th:text="#{msg.ListStudents}" /></td>
</tr>
</table>
</body> </body>
</html> </html>

View File

@ -9,16 +9,28 @@
<table border="1"> <table border="1">
<thead> <thead>
<tr> <tr>
<th th:text="#{msg.id}"></th> <th th:text="#{msg.id}" />
<th th:text="#{msg.name}"></th> <th th:text="#{msg.name}" />
<th th:text="#{msg.gender}" />
<th th:text="#{msg.percent}" />
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr th:each="student: ${students}"> <tr th:each="student: ${students}">
<td th:text="${#conversions.convert(student.id,'Float')}"></td> <td th:text="${student.id}" />
<td th:text="${{student.name}}"></td> <td th:text="${{student.name}}" />
<td th:switch="${student.gender}"><span th:case="'M'"
th:text="Male" /> <span th:case="'F'" th:text="Female" /></td>
<td th:text="${#conversions.convert(student.percentage, 'Integer')}" />
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div>
<p>
<a th:href="@{/}" th:text="#{msg.Home}" />
</p>
</div>
</body> </body>
</html> </html>