I am trying to display data
in a table row
. However it is just showing the var name
as output, e.g:
Name | age
User1| {age}
I am using Spring-MVC
along with Spring Boot
. I have created other mapping classes and their data is showing correctly in HTML <p> tags
.
My Controller:
@Controller
public class MyController {
@RequestMapping("/age")
public String age(@RequestParam(value="age", required=false, defaultValue="5") String age, Model model) {
model.addAttribute("age", age);
return "age";
}
}
age.html: (uses ThymeLeaf)
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Age Table</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<table border="1">
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<tr>
<td>User1</td>
<td>${age}</td>
</tr>
</table>
</body>
</html>
Try this :
If you have a list of age like this:
then try this: