Mybatis的select方法
生活随笔
收集整理的這篇文章主要介紹了
Mybatis的select方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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;elsereturn 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;elsereturn accountList.get(0); }總結
以上是生活随笔為你收集整理的Mybatis的select方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mybatis的insert方法
- 下一篇: Mybatis的update方法