欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

详解Mybatis中的select方法

程序员文章站 2024-02-18 21:00:46
selectbyid方法 根据id,查询记录 public void updaterecycleassaybusinessitemcharge(string...

selectbyid方法

根据id,查询记录

public void updaterecycleassaybusinessitemcharge(string id) {
  assaybusinessitemcharge assaybusinessitemcharge = assaybusinessitemchargeservice.selectbyid(id);
  assaybusinessitemcharge.setrecordstatus(recordstatusenum.valid.getvalue());
  assaybusinessitemchargeservice.update(assaybusinessitemcharge);
}

selectbyexample方法

根据实体字段,查询记录

public account findbyaccountname(string accountname) {
  accountexample accountexample = new accountexample();
  accountexample.criteria criteria = accountexample.createcriteria();
  criteria.andaccountnameequalto(accountname);
  list<account> accountlist = accountservice.selectbyexample(accountexample);
  if (accountlist == null || accountlist.size() != 1)
    return null;
  else
    return accountlist.get(0);
}

查询所有list

传一个空的实体,不要给赋字段值

public account findbyaccountname(string accountname) {
  accountexample accountexample = new accountexample();
  accountexample.criteria criteria = accountexample.createcriteria();
  list<account> accountlist = accountservice.selectbyexample(accountexample);
  if (accountlist == null || accountlist.size() != 1)
    return null;
  else
    return accountlist.get(0);
}

总结

以上所述是小编给大家介绍的mybatis中的select方法,希望对大家有所帮助