1.实体:
- public class Order {
- private int id;
- private Date orderDate;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public Date getOrderDate() {
- return orderDate;
- }
- public void setOrderDate(Date orderDate) {
- this.orderDate = orderDate;
- }
- @Override
- public String toString() {
- return "Order [id=" + id + "]";
- }
- public Order() {
- super();
- }
- }
2.dao查找最大的ID
- private static final Class CLAZZ = Order.class;
- public Object findMaxID() {
- String sql = "select max(id) from tb_order";
- Object[] params = null;
- return super.find(sql, CLAZZ, params);
- }
3.返回值总是0
4.SQL语句改成:
String sql = "select max(id) as id from tb_order";
5.最后实体Order中的id能获得最大的值