mybatis操作資料庫的過程中,如果只考慮單表操作,mapper和dao層基本80%的都是固定的,故而可以使用工具進行生成,文末提供自己編寫的工具(基於mysql存儲過程):作者其實就是使用(mybatis-generator)這個工具過程中,有些想法,實踐下,編寫時很多實現留了口子,後續方便集成 ...
mybatis操作資料庫的過程中,如果只考慮單表操作,mapper和dao層基本80%的都是固定的,故而可以使用工具進行生成,文末提供自己編寫的工具(基於mysql存儲過程):
作者其實就是使用(mybatis-generator)這個工具過程中,有些想法,實踐下,編寫時很多實現留了口子,後續方便集成到開發框架中。
工具提供 mapper,dao層功能如下:
通用查詢,返回對象
通用查詢,返回集合
通用主鍵查詢,返回集合
通過條件和主鍵in查詢,返回集合
通過主鍵更新
通過條件更新
通過條件和主鍵in更新
單條插入,id自增
單條插入,id不自增
批量插入
(如需定製化生成代碼,請翻閱前幾篇文章,本文僅將通用性代碼抽取出來:https://www.cnblogs.com/wanglifeng717/p/15839391.html)
- 1.查詢部分示例
因為查詢根據不同條件sql不同,可以使用動態語句。使用對象拼接查詢條件。此時mapper層只需要一個方法。(工具自動生成代碼如下)
// 通用查詢,返回對象 @Select({ "<script> ", "select t.id as id,t.create_time as create_time,t.last_update_time as last_update_time,t.login_name as login_name,t.login_password as login_password,t.status as status,t.remark as remark,t.admin_user_id as admin_user_id ", "from tbl_sapo_admin_account t ", "<where> ", "<if test='queryObj!=null'>", "<if test = 'queryObj.id!=null'> and id=#{queryObj.id,jdbcType=INTEGER} </if>" , "<if test = 'queryObj.create_time!=null'> and create_time=#{queryObj.createTime,jdbcType=TIMESTAMP} </if>" , "<if test = 'queryObj.last_update_time!=null'> and last_update_time=#{queryObj.lastUpdateTime,jdbcType=TIMESTAMP} </if>" , "<if test = 'queryObj.loginName !=null and queryObj.loginName !='''> and login_name=#{queryObj.loginName,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.loginPassword !=null and queryObj.loginPassword !='''> and login_password=#{queryObj.loginPassword,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.status!=null'> and status=#{queryObj.status,jdbcType=INTEGER} </if>" , "<if test = 'queryObj.remark !=null and queryObj.remark !='''> and remark=#{queryObj.remark,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.admin_user_id!=null'> and admin_user_id=#{queryObj.adminUserId,jdbcType=INTEGER} </if>" , "</if>", "</where> ", "</script>" }) SapoAdminAccount getSapoAdminAccount(@Param("queryObj") SapoAdminAccount sapoAdminAccountForQuery);
- 2.更新部分示例
更新的前提基本都是已經查出來該記錄,直接根據主鍵更新即可。並沒有很多花樣。(工具自動生成代碼如下)
// 通過主鍵更新 @Update({ "update tbl_sapo_admin_account set ", "create_time=#{updateObj.createTime,jdbcType=TIMESTAMP} ,last_update_time=#{updateObj.lastUpdateTime,jdbcType=TIMESTAMP} ,login_name=#{updateObj.loginName,jdbcType=VARCHAR} ,login_password=#{updateObj.loginPassword,jdbcType=VARCHAR} ,status=#{updateObj.status,jdbcType=INTEGER} ,remark=#{updateObj.remark,jdbcType=VARCHAR} ,admin_user_id=#{updateObj.adminUserId,jdbcType=INTEGER} ", "where id = #{updateObj.id,jdbcType=INTEGER} " }) int updateSapoAdminAccountByPrimaryKey(@Param("updateObj") SapoAdminAccount sapoAdminAccountForUpdate);
如果更新的條件是不確定的,更新的內容也不確定,可以使用動態語句,基本一個更新語句包打天下(工具自動生成代碼如下:)
// 通過條件更新 @Update({ "<script> ", "update tbl_sapo_admin_account ", "<set>", "<if test='updateObj!=null'>", "<if test = 'updateObj.create_time!=null'> create_time=#{updateObj.createTime,jdbcType=TIMESTAMP} , </if>" , "<if test = 'updateObj.last_update_time!=null'> last_update_time=#{updateObj.lastUpdateTime,jdbcType=TIMESTAMP} , </if>" , "<if test = 'updateObj.loginName !=null and updateObj.loginName !='''> login_name=#{updateObj.loginName,jdbcType=VARCHAR} , </if>" , "<if test = 'updateObj.loginPassword !=null and updateObj.loginPassword !='''> login_password=#{updateObj.loginPassword,jdbcType=VARCHAR} , </if>" , "<if test = 'updateObj.status!=null'> status=#{updateObj.status,jdbcType=INTEGER} , </if>" , "<if test = 'updateObj.remark !=null and updateObj.remark !='''> remark=#{updateObj.remark,jdbcType=VARCHAR} , </if>" , "<if test = 'updateObj.admin_user_id!=null'> admin_user_id=#{updateObj.adminUserId,jdbcType=INTEGER} , </if>" , "</if>", "</set>", "<where>", "<if test='queryObj!=null'>", "<if test = 'queryObj.id!=null'> and id=#{queryObj.id,jdbcType=INTEGER} </if>" , "<if test = 'queryObj.create_time!=null'> and create_time=#{queryObj.createTime,jdbcType=TIMESTAMP} </if>" , "<if test = 'queryObj.last_update_time!=null'> and last_update_time=#{queryObj.lastUpdateTime,jdbcType=TIMESTAMP} </if>" , "<if test = 'queryObj.loginName !=null and queryObj.loginName !='''> and login_name=#{queryObj.loginName,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.loginPassword !=null and queryObj.loginPassword !='''> and login_password=#{queryObj.loginPassword,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.status!=null'> and status=#{queryObj.status,jdbcType=INTEGER} </if>" , "<if test = 'queryObj.remark !=null and queryObj.remark !='''> and remark=#{queryObj.remark,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.admin_user_id!=null'> and admin_user_id=#{queryObj.adminUserId,jdbcType=INTEGER} </if>" , "</if>", "</where>", "</script>" }) int updateSapoAdminAccount(@Param("updateObj") SapoAdminAccount sapoAdminAccountForUpdate,@Param("queryObj") SapoAdminAccount sapoAdminAccountForQuery);
- 3.插入部分示例
// 單條插入:id自增 @Insert({ "insert into tbl_sapo_admin_account ", "(id,create_time,last_update_time,login_name,login_password,status,remark,admin_user_id)", "values ", "(#{item.id,jdbcType=INTEGER} ,#{item.createTime,jdbcType=TIMESTAMP} ,#{item.lastUpdateTime,jdbcType=TIMESTAMP} ,#{item.loginName,jdbcType=VARCHAR} ,#{item.loginPassword,jdbcType=VARCHAR} ,#{item.status,jdbcType=INTEGER} ,#{item.remark,jdbcType=VARCHAR} ,#{item.adminUserId,jdbcType=INTEGER} ) " }) @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") int insertSapoAdminAccount(@Param("item") SapoAdminAccount sapoAdminAccount);
// 批量插入 @Insert({ "<script> ", "insert into tbl_sapo_admin_account ( id,create_time,last_update_time,login_name,login_password,status,remark,admin_user_id ) values", "<foreach collection='itemList' item='item' index='index' open='(' separator='),(' close=')'>", "#{item.id,jdbcType=INTEGER} ,#{item.createTime,jdbcType=TIMESTAMP} ,#{item.lastUpdateTime,jdbcType=TIMESTAMP} ,#{item.loginName,jdbcType=VARCHAR} ,#{item.loginPassword,jdbcType=VARCHAR} ,#{item.status,jdbcType=INTEGER} ,#{item.remark,jdbcType=VARCHAR} ,#{item.adminUserId,jdbcType=INTEGER} ", "</foreach>", "</script>" }) int batchInsertSapoAdminAccount(@Param("itemList") List<SapoAdminAccount> sapoAdminAccountList);
工具生成dao層代碼示例:
// 批量插入 @SuppressWarnings("unchecked") public int batchInsertSapoAdminAccount(Object object) { // 類型轉換,支持單個對象或者集合形式作為入參 List<SapoAdminAccount> list = null; if (object instanceof SapoAdminAccount) { list = new ArrayList<>(); list.add((SapoAdminAccount) object); } else if (object instanceof List) { for (Object o : (List<?>) object) { if (!(o instanceof SapoAdminAccount)) { throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(),ResultInfo.SYS_INNER_ERROR.getDesc() + ",error element: " + o.toString() + ",object type is error for batch insert" + BizLogUtils.getValueOfBizId()); } } list = (List<SapoAdminAccount>) object; } else { throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(),ResultInfo.SYS_INNER_ERROR.getDesc() + ",object type is error for batch insert" + BizLogUtils.getValueOfBizId()); } // 如果集合為空則報異常 if (list == null || list.size() == 0) { throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(),ResultInfo.SYS_INNER_ERROR.getDesc() + ",batch insert empty ,bizId=" + BizLogUtils.getValueOfBizId()); } // 插入閾值, 每多少條commit一次,預設是200條做一次。 int threshold = 200; int result = 0; int sum = list.size(); int end = 0; for (int i = 0; i < sum; i = i + threshold) { end = i + threshold > sum ? sum : i + threshold; try { result += mapper.batchInsertSapoAdminAccount(list.subList(i, end)); } catch (Exception e) { // 根據業務做補償機制,例如通過end值,將之前插入的值全部刪除或者狀態翻轉為無效 batchInsertSapoAdminAccountFailOffset(list.subList(0, end)); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(),ResultInfo.SYS_INNER_ERROR.getDesc()+ ",end value: " + end + ",batch insert has error,offset [batch insert error] success ,bizId=" + BizLogUtils.getValueOfBizId(), e); } } return result; } // 批量插入失敗後,進行相關補償操作 private void batchInsertSapoAdminAccountFailOffset(List<SapoAdminAccount> list) { // 補償操作,可以比插入操作的閾值大一點, 每多少條commit一次,預設是400條做一次。 int threshold = 400; int sum = list.size(); int end = 0; for (int i = 0; i < sum; i = i + threshold) { end = i + threshold > sum ? sum : i + threshold; try { // TODO 批量插入失敗後,需要進行補償的操作,例如:將之前插入的值全部刪除或者狀態翻轉為無效 //List<Integer> idList = list.subList(i, end).stream().map(SapoAdminAccount::getId).collect(Collectors.toList()); //SapoAdminAccount sapoAdminAccountForUpdate = new SapoAdminAccount(); //sapoAdminAccountForUpdate.setxx(); //updateSapoAdminAccount(idList,null,sapoAdminAccountForUpdate); } catch (Exception e) { // 如果做業務補償的時候也失敗了,只能將重要信息列印在日誌裡面,運維干預進行恢復了 throw new BusinessException( ResultInfo.SYS_INNER_ERROR.getCode(),ResultInfo.SYS_INNER_ERROR.getDesc() + ", [offset batch insert error] failed ,"+ ",bizId: " + BizLogUtils.getValueOfBizId(), e); } } } // 單條插入:id自增 public int insertSapoAdminAccount(SapoAdminAccount sapoAdminAccount){ if(sapoAdminAccount == null ){ bizLogger.warn(" insert tbl_sapo_admin_account sapoAdminAccount is null "); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " sapoAdminAccount is null , bizId=" + BizLogUtils.getValueOfBizId()); } int insertResult =0; try { insertResult = mapper.insertSapoAdminAccount(sapoAdminAccount); } catch (DuplicateKeyException e) { bizLogger.error(" update tbl_sapo_admin_account duplicateKeyException ,sapoAdminAccount : " + sapoAdminAccount.toString()); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " duplicate exception ,bizId=" + BizLogUtils.getValueOfBizId(),e); } if (insertResult==0) { bizLogger.warn("insert tbl_sapo_admin_account result == 0 , sapoAdminAccount: "+sapoAdminAccount.toString()); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(),ResultInfo.SYS_INNER_ERROR.getDesc() + " ,bizId="+BizLogUtils.getValueOfBizId()); } return insertResult; } // 單條插入:id不自增 public void insertSapoAdminAccount(SapoAdminAccount sapoAdminAccount){ if(sapoAdminAccount == null ){ bizLogger.warn(" insert tbl_sapo_admin_account sapoAdminAccount is null "); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " sapoAdminAccount is null , bizId=" + BizLogUtils.getValueOfBizId()); } int insertResult =0; try { insertResult = mapper.insertSapoAdminAccount(sapoAdminAccount); } catch (DuplicateKeyException e) { bizLogger.error(" update tbl_sapo_admin_account duplicateKeyException ,sapoAdminAccount : " + sapoAdminAccount.toString()); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " duplicate exception ,bizId=" + BizLogUtils.getValueOfBizId(),e); } if (insertResult!=1) { bizLogger.warn("insert tbl_sapo_admin_account result != 1 , sapoAdminAccount: "+sapoAdminAccount.toString()); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(),ResultInfo.SYS_INNER_ERROR.getDesc() + " ,bizId="+BizLogUtils.getValueOfBizId()); } } // 通用主鍵查詢,返回對象 public SapoAdminAccount getSapoAdminAccountByPrimaryKey(Integer id){ if(id == null){ bizLogger.warn(" select tbl_sapo_admin_account id is null "); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " id is null , bizId=" + BizLogUtils.getValueOfBizId()); } SapoAdminAccount sapoAdminAccount = mapper.getSapoAdminAccountByPrimaryKey(id); if(sapoAdminAccount == null){ bizLogger.warn(" select tbl_sapo_admin_account by primary key ,but find null ,id : " + id.toString()); throw new BusinessException(ResultInfo.NO_DATA.getCode(),ResultInfo.NO_DATA.getDesc() + " ,bizId="+BizLogUtils.getValueOfBizId()); } return sapoAdminAccount; } // 通用查詢,返回對象 public SapoAdminAccount getSapoAdminAccount(SapoAdminAccount sapoAdminAccountForQuery){ if(sapoAdminAccountForQuery == null){ bizLogger.warn(" select tbl_sapo_admin_account sapoAdminAccountForQuery is null "); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " sapoAdminAccountForQuery is null , bizId=" + BizLogUtils.getValueOfBizId()); } SapoAdminAccount sapoAdminAccount = mapper.getSapoAdminAccount(sapoAdminAccountForQuery); if(sapoAdminAccount == null){ bizLogger.warn(" select tbl_sapo_admin_account result is null ,sapoAdminAccountForQuery : " + sapoAdminAccountForQuery.toString()); throw new BusinessException(ResultInfo.NO_DATA.getCode(),ResultInfo.NO_DATA.getDesc() + " ,bizId="+BizLogUtils.getValueOfBizId()); } return sapoAdminAccount; } // 通用查詢,返回集合 public List<SapoAdminAccount> getSapoAdminAccountList(SapoAdminAccount sapoAdminAccountForQuery){ if(sapoAdminAccountForQuery == null){ bizLogger.warn(" select tbl_sapo_admin_account sapoAdminAccountForQuery is null "); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " sapoAdminAccountForQuery is null , bizId=" + BizLogUtils.getValueOfBizId()); } List<SapoAdminAccount> sapoAdminAccountList = mapper.getSapoAdminAccountList(sapoAdminAccountForQuery); if(sapoAdminAccountList == null || sapoAdminAccountList.size()==0){ bizLogger.warn(" select tbl_sapo_admin_account List is null or size=0 ,sapoAdminAccountForQuery : " + sapoAdminAccountForQuery.toString()); throw new BusinessException(ResultInfo.NO_DATA.getCode(),ResultInfo.NO_DATA.getDesc() + " ,bizId="+BizLogUtils.getValueOfBizId()); } return sapoAdminAccountList; } // 通過主鍵更新 public void updateSapoAdminAccountByPrimaryKey(SapoAdminAccount sapoAdminAccountForUpdate){ if(sapoAdminAccountForUpdate == null){ bizLogger.warn(" update tbl_sapo_admin_account sapoAdminAccountForUpdate is null "); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " sapoAdminAccountForUpdate is null , bizId=" + BizLogUtils.getValueOfBizId()); } int updateResult = 0; try { updateResult = mapper.updateSapoAdminAccountByPrimaryKey(sapoAdminAccountForUpdate); } catch (DuplicateKeyException e) { bizLogger.warn(" update tbl_sapo_admin_account duplicateKeyException ,sapoAdminAccountForUpdate : " + sapoAdminAccountForUpdate.toString()); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " duplicate exception ,bizId=" + BizLogUtils.getValueOfBizId(),e); } /* if (updateResult!=1) { bizLogger.warn("update tbl_sapo_admin_account result !=1 [updateResult, sapoAdminAccountForUpdate] : "+updateResult+","+ sapoAdminAccountForUpdate.toString()); throw new BusinessException(ResultInfo.NO_DATA.getCode(),ResultInfo.NO_DATA.getDesc() + " ,bizId="+BizLogUtils.getValueOfBizId()); } */ } // 通過條件和主鍵in更新 public void updateSapoAdminAccount(List<Integer> idListForQuery,SapoAdminAccount sapoAdminAccountForQuery,SapoAdminAccount sapoAdminAccountForUpdate){ if(idListForQuery == null && sapoAdminAccountForQuery==null ){ bizLogger.warn(" update tbl_sapo_admin_account idListForQuery and sapoAdminAccountForQuery is null at same time"); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " idListForQuery and sapoAdminAccountForQuery is null at same time , bizId=" + BizLogUtils.getValueOfBizId()); } if(sapoAdminAccountForUpdate == null ){ bizLogger.warn(" update tbl_sapo_admin_account sapoAdminAccountForUpdate is null "); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " sapoAdminAccountForUpdatey is null , bizId=" + BizLogUtils.getValueOfBizId()); } int updateResult = 0; try { updateResult = mapper.updateSapoAdminAccount(idListForQuery,sapoAdminAccountForQuery,sapoAdminAccountForUpdate); } catch (DuplicateKeyException e) { bizLogger.error(" update tbl_sapo_admin_account duplicateKeyException ,sapoAdminAccountForQuery : " + sapoAdminAccountForQuery.toString()+" ; idListForQuery: "+idListForQuery); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " duplicate exception ,bizId=" + BizLogUtils.getValueOfBizId(),e); } /* if (updateResult!=1) { bizLogger.warn("update tbl_sapo_admin_account result !=1 [updateResult, sapoAdminAccountForQuery,idListForQuery] : "+updateResult+","+ sapoAdminAccountForQuery.toString()+","+idListForQuery); throw new BusinessException(ResultInfo.NO_DATA.getCode(),ResultInfo.NO_DATA.getDesc() + " ,bizId="+BizLogUtils.getValueOfBizId()); } */ } // 通過條件和主鍵in查詢,返回集合 public List<SapoAdminAccount> getSapoAdminAccountList( List<Integer> idListForQuery, SapoAdminAccount sapoAdminAccountForQuery){ if(idListForQuery == null && sapoAdminAccountForQuery == null){ bizLogger.warn(" select tbl_sapo_admin_account idListForQuery && sapoAdminAccountForQuery is null at same time"); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " idListForQuery && sapoAdminAccountForQuery is null at same time , bizId=" + BizLogUtils.getValueOfBizId()); } List<SapoAdminAccount> sapoAdminAccountList = mapper.getSapoAdminAccountList(idListForQuery,sapoAdminAccountForQuery); if(sapoAdminAccountList == null || sapoAdminAccountList.size()==0){ bizLogger.warn(" select tbl_sapo_admin_account ,but result list is null or size=0 ,sapoAdminAccountForQuery : " + sapoAdminAccountForQuery.toString()+"; idListForQuery : "+idListForQuery.toString()); throw new BusinessException(ResultInfo.NO_DATA.getCode(),ResultInfo.NO_DATA.getDesc() + " ,bizId="+BizLogUtils.getValueOfBizId()); } return sapoAdminAccountList; } // 通過條件更新 public void updateSapoAdminAccount(SapoAdminAccount sapoAdminAccountForUpdate,SapoAdminAccount sapoAdminAccountForQuery){ if(sapoAdminAccountForUpdate == null || sapoAdminAccountForQuery==null ){ bizLogger.warn(" update tbl_sapo_admin_account sapoAdminAccountForUpdate or sapoAdminAccountForQuery is null "); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " sapoAdminAccountForUpdate or sapoAdminAccountForQuery is null , bizId=" + BizLogUtils.getValueOfBizId()); } int updateResult = 0; try { updateResult = mapper.updateSapoAdminAccount(sapoAdminAccountForUpdate,sapoAdminAccountForQuery); } catch (DuplicateKeyException e) { bizLogger.error(" update tbl_sapo_admin_account duplicateKeyException ,sapoAdminAccountForQuery : " + sapoAdminAccountForQuery.toString()); throw new BusinessException(ResultInfo.SYS_INNER_ERROR.getCode(), ResultInfo.SYS_INNER_ERROR.getDesc() + " duplicate exception ,bizId=" + BizLogUtils.getValueOfBizId(),e); } /* if (updateResult!=1) { bizLogger.warn("update tbl_sapo_admin_account result !=1 [updateResult, sapoAdminAccountForQuery] : "+updateResult+","+ sapoAdminAccountForQuery.toString()); throw new BusinessException(ResultInfo.NO_DATA.getCode(),ResultInfo.NO_DATA.getDesc() + " ,bizId="+BizLogUtils.getValueOfBizId()); } */ }View Code
工具生成mapper層代碼示例:
// 通用查詢,返回對象 @Select({ "<script> ", "select t.id as id,t.create_time as create_time,t.last_update_time as last_update_time,t.login_name as login_name,t.login_password as login_password,t.status as status,t.remark as remark,t.admin_user_id as admin_user_id ", "from tbl_sapo_admin_account t ", "<where> ", "<if test='queryObj!=null'>", "<if test = 'queryObj.id!=null'> and id=#{queryObj.id,jdbcType=INTEGER} </if>" , "<if test = 'queryObj.create_time!=null'> and create_time=#{queryObj.createTime,jdbcType=TIMESTAMP} </if>" , "<if test = 'queryObj.last_update_time!=null'> and last_update_time=#{queryObj.lastUpdateTime,jdbcType=TIMESTAMP} </if>" , "<if test = 'queryObj.loginName !=null and queryObj.loginName !='''> and login_name=#{queryObj.loginName,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.loginPassword !=null and queryObj.loginPassword !='''> and login_password=#{queryObj.loginPassword,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.status!=null'> and status=#{queryObj.status,jdbcType=INTEGER} </if>" , "<if test = 'queryObj.remark !=null and queryObj.remark !='''> and remark=#{queryObj.remark,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.admin_user_id!=null'> and admin_user_id=#{queryObj.adminUserId,jdbcType=INTEGER} </if>" , "</if>", "</where> ", "</script>" }) SapoAdminAccount getSapoAdminAccount(@Param("queryObj") SapoAdminAccount sapoAdminAccountForQuery); // 通用查詢,返回集合 @Select({ "<script> ", "select t.id as id,t.create_time as create_time,t.last_update_time as last_update_time,t.login_name as login_name,t.login_password as login_password,t.status as status,t.remark as remark,t.admin_user_id as admin_user_id ", "from tbl_sapo_admin_account t ", "<where> ", "<if test='queryObj!=null'>", "<if test = 'queryObj.id!=null'> and id=#{queryObj.id,jdbcType=INTEGER} </if>" , "<if test = 'queryObj.create_time!=null'> and create_time=#{queryObj.createTime,jdbcType=TIMESTAMP} </if>" , "<if test = 'queryObj.last_update_time!=null'> and last_update_time=#{queryObj.lastUpdateTime,jdbcType=TIMESTAMP} </if>" , "<if test = 'queryObj.loginName !=null and queryObj.loginName !='''> and login_name=#{queryObj.loginName,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.loginPassword !=null and queryObj.loginPassword !='''> and login_password=#{queryObj.loginPassword,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.status!=null'> and status=#{queryObj.status,jdbcType=INTEGER} </if>" , "<if test = 'queryObj.remark !=null and queryObj.remark !='''> and remark=#{queryObj.remark,jdbcType=VARCHAR} </if>" , "<if test = 'queryObj.admin_user_id!=null'> and admin_user_id=#{queryObj.adminUserId,jdbcType=INTEGER} </if>" , "</if>", "</where> ", "</script>" }) List<SapoAdminAccount> getSapoAdminAccountList(@Param("queryObj") SapoAdminAccount sapoAdminAccountForQuery); // 通過主鍵查詢,返回對象 @Select({ "select t.id as id,t.create_time as create_time,t.last_update_time as last_update_time,t.login_name as login_name,t.login_password as login_password,t.status as status,t.remark as remark,t.admin_user_id as admin_user_id ", "from tbl_sapo_admin_account t ", "where id = #{id,jdbcType=INTEGER}" }) SapoAdminAccount getSapoAdminAccountByPrimaryKey(Integer id); // 通過條件和主鍵in查詢,返回集合 @Select({ "<script> ", "select t.id as id,t.creat