here is my following dao implementaion
@Override
public List<UserAddress> getAddresses(int pageid,int total) {
String sql = "select * FROM user_addresses order by id desc limit "+(pageid-1)+","+total;
List<UserAddress> userAddresses = jdbcTemplate.query(sql, new RowMapper<UserAddress>() {
@Override
public UserSessionLog mapRow(ResultSet rs, int rowNum) throws SQLException {
UserAddress userAdd = new UserAddress();
userAdd.setId(rs.getInt("id"));
userAdd.setId(rs.getString("city"));
return userSession;
}
});
return userAddresses;
}
in the above dao implementaion, i list all the user addresses, trying to list with limit
@RequestMapping("/userAddresses/{pageid}")
public ModelAndView userAddresses(@PathVariable int pageid) {
int total=5;
if(pageid==1){}
else{
pageid=(pageid-1)*total+1;
}
List<UserAddress> listAddresses = userAddressFacade.getAddresses(pageid,total);
return new ModelAndView("userAddresses", "listAddresses", listAddresses);
}
this is my view part,
<table class="table table-condensed">
<thead>
<tr>
<th>Address1</th>
<th>City</th>
</tr>
</thead>
<tbody>
<c:if test="${not empty addresses}">
<c:forEach var="address" items="${addresses}">
<tr>
<td>${address.address1}</td>
<td>${address.city}</td>
</tr>
</c:forEach>
</c:if>
</tbody>
</table>
<br/>
<a href="/pro/userAddress/1">1</a>
<a href="/pro/userAddress/2">2</a>
<a href="/pro/userAddress/3">3</a>
I have hardcoded the pagination part, do any one have idea, how to do pagination. i am newbie to java jdbcTemplate,