Creative crypter Creative crypter - 5 months ago 25
SQL Question

Spring hibernate mvc - loop in frontend

I created a web application based on spring 4.3 and hibernate 5.2,

when it comes to querying for data and display data in frontend(jsp), i get stuck...

controller:

@RequestMapping("/test")
public ModelAndView helloWorld() {

List<Article> articles = articleDao.list();

ModelAndView model = new ModelAndView("test");

model.addObject("articles", articles);

return model;

}


test.jsp:

<c:forEach var="article" items="${articles}">
${article.name} <br/>
</c:forEach>


i have four records in database and this is displayed in frontend:

<c:foreach items="[com.example.app.model.Article@41d04f4b, com.example.app.model.Article@1b56d335, com.example.app.model.Article@30f1547d, com.example.app.model.Article@5e30ea41]" var="article">
<br>
</c:foreach>


When i log hibernate sql statement using log4j2, i get this output:

select
article0_.id as id1_0_,
article0_.name as name2_0_,
from
s_articles article0_


Anybody can help with this issue?
For now i just want to query for data from my database(articles) and display them on frontend (.jsp-pages).

Thanks and Greetings!!

Answer

Have you added

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

to your file ?

I think You will have to add the JSTL for using c:forEach, doing this should fix your issue.