30 lines
845 B
Java
30 lines
845 B
Java
|
package example.dao;
|
||
|
|
||
|
import example.model.Orders;
|
||
|
import example.utils.DBUtils;
|
||
|
import org.apache.commons.dbutils.QueryRunner;
|
||
|
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||
|
|
||
|
import java.util.List;
|
||
|
|
||
|
public class OrdersDao {
|
||
|
private final QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());
|
||
|
|
||
|
|
||
|
public List<Orders> getAllOrders() {
|
||
|
String sql = "select id,user_id userId,order_date orderDate,total_price totalPrice,address ,remark from orders o ";
|
||
|
try {
|
||
|
return queryRunner.query(sql, new BeanListHandler<>(Orders.class));
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
OrdersDao ordersDao = new OrdersDao();
|
||
|
System.out.println(ordersDao.getAllOrders());
|
||
|
}
|
||
|
}
|