跳转到内容

Java 持久性/Ebean/快速入门 - example

来自 Wikibooks,为开放世界开放书籍

一些基本查询

// find a customer using their Id
Customer customer = Ebean.find(Customer.class, 7);

// find all customers
List<Customer> list = Ebean.find(Customer.class).findList();

// find customers with names starting with Rob%
List<Customer> customers = 
    Ebean.find(Customer.class)
        .where().startsWith("name","Rob")
        .findList();

保存和删除

// find a customer using their Id
Customer customer = Ebean.find(Customer.class, 7);
customer.setName("Cool Customer");

// save will update the customer
Ebean.save(customer);

Customer newCust = new Customer();
newCust.setName("Super Cust");
...

// save will insert the new customer
Ebean.save(newCust);
华夏公益教科书