0

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!

4

1 回答 1

1

You can't use a parameter to refer to column values. See this answer for details.

于 2012-04-10T19:14:08.773 回答