当前位置: 移动技术网 > IT编程>开发语言>Java > 详解Mybatis中的select方法

详解Mybatis中的select方法

2019年07月19日  | 移动技术网IT编程  | 我要评论

永恒精魄,桂林九株浓缩液,小李获赠玫瑰金人

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方法,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网