I'm trying to implement sorting and pagination on server side in my spring mvc application.
The problem is that after call JdbcTemplate.query()
method I get unsorted array list.
My query code:
List<Ingredient> ingredients = query("SELECT * FROM Ingredients ORDER BY ? ? LIMIT ?, ?",
new Object[]{"title", "ASC", 0, 50},
new IngredientsMapper());
My mapper code:
public class IngredientsMapper implements ParameterizedRowMapper {
@Override
public Ingredient mapRow(ResultSet rs, int rowNum) throws SQLException {
Ingredient ingredient = new Ingredient();
ingredient.setId(rs.getInt("IngredientID"));
ingredient.setTitle(rs.getString("title"));
ingredient.setCost(rs.getFloat("cost"));
ingredient.setDescription(rs.getString("description"));
ingredient.setUnits(rs.getString("units"));
return ingredient;
}
}
What I'm doing wrong?
Thanks for any help. Have a good day!