1、自定义的实体类:
public class Order implements Serializable {
private String orderId;
private String userId;
private String text;
private Integer status;
//省略set\get
}
2、自定义类实现RowMapper接口
public class OrderRowMapper implements RowMapper<Order> {
@Override
public Order mapRow(ResultSet resultSet, int i) throws SQLException {
String orderId = resultSet.getString("order_id");
String userId = resultSet.getString("user_id");
String text = resultSet.getString("text");
String status = resultSet.getString("status");
Order order = new Order();
order.setOrderId(orderId);
order.setUserId(userId);
order.setText(text);
order.setStatus(Integer.parseInt(status));
return order;
}
}
3、查询方法
public List<Order> getOrderByStatusIsZero() {
String sql = "select * from order_master_back where status = 0";
List<Order> query = jdbcTemplate.query(sql, new OrderRowMapper());
return query;
}