Java – converts the original class object to a specific class object
•
Java
I'm studying hibernate and spring
Here I attach my method
public List getAnalyticsbyid(String userId)
{
Session session=sessionFactory.openSession();
String querystring="SELECT DISTINCT bounces,visits,landingPagePath FROM AnalyticsDataFeedBean where userId='"+userId+"' ORDER BY bounces DESC";
Query query=session.createQuery(querystring).addEntity(AnalyticsDataFeedBean.class);
query.setMaxResults(10);
return query.list();
}
Solution
Your HQL query returns list < object [] > you can change the method signature to
public List<Object[]> getAnalyticsbyid(String userId)
And iterate over the list and print the details where this method is called
List<Object[]> list = getAnalyticsbyid("user");
for (Object[] objects : list) {
for (Object object : objects) {
System.out.print(object);
System.out.print("\t");
}
System.out.println();
}
If you want to display it as a table in a JSP file, start with the following code snippet
<table>
<tr>
<th>bounces</th>
<th>visits</th>
<th>landingPagePath</th>
</tr>
<c:forEach items="${analytics}" var="objects">
<tr>
<c:forEach items="${objects}" var="object">
<td><c:out value="${object}"/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
