Reputation: 339
MySQL
and when I am trying to return it to the HTML
page for displaying. It is not being display but it can be seen as a list
.Controller
@GetMapping(value = "/successful")
public ModelAndView registered(Model model) {
List<Student> student = dao.getStudents();
Map<String, Object> params = new HashMap<>();
System.out.println(params);
params.put("students", student);
return new ModelAndView("index", params);
}
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>DOB</th>
<th>Address</th>
</tr>
<tr th:each="student : ${students}">
<td th:text="${student.name}"></td>
<td th:text="${student.dob}"></td>
<td th:text="${student.address}"></td>
</tr>
</table>
<script>
var data = ${students};
console.log(data);
</script>
</body>
</html>
<td th:text="${student.name}"></td>
is empty.Upvotes: 0
Views: 1200
Reputation: 1735
Try this:
@GetMapping(value = "/successful")
public String registered(Model model) {
List<Student> students = dao.getStudents();
model.addAttribute("students", students);
return "index";
}
Upvotes: 1