mybatisplus exception:One record is expected, but the query result is multiple records


mybatisplus exception:One record is expected, but the query result is multiple records

原因:使用getOne(queryWrapper),查出了多條數據

解決方案:如果想取一條並不想報錯時使用getOne(queryWrapper,false)

源碼:

 public interface IService<T> {
    /**
    * 根據 Wrapper,查詢一條記錄 <br/>
    * <p>結果集,如果是多個會拋出異常
    */
   default T getOne(Wrapper<T> queryWrapper) {
       return getOne(queryWrapper, true);
  }

   /**
    * 根據 Wrapper,查詢一條記錄
    * @param throwEx     有多個 result 是否拋出異常(false,不拋出異常,取一條)
    */
   T getOne(Wrapper<T> queryWrapper, boolean throwEx);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM