简单查询

QuickDAO提供了一些便捷方法.当您只是根据单个条件查询或者只需要返回单条结果时,这些方法是非常有用的.

Person实体类

  1. public class Person {
  2. @Id(strategy = IdStrategy.AutoIncrement)
  3. private long id;
  4. private String username;
  5. private String password;
  6. }

简单查询实例

  1. //根据id查询
  2. //对应SQL: select id,username,password from person where id = 1
  3. User user1 = dao.fetch(Person.class,1);
  4. //根据单个属性查询,返回列表的第一条数据
  5. //对应SQL: select id,username,password from person where username = 'quickdao'
  6. User user2 = dao.fetch(User.class,"username","quickdao");
  7. //根据单个属性查询,返回列表
  8. //对应SQL: select id,username,password from person where username = 'quickdao'
  9. List<User> userList = dao.fetchList(User.class,"username","quickdao");

fetch方法默认只会返回列表的第一条记录,若返回列表存在多条记录,则会直接返回第一条记录