springboot中實現(xiàn)通過后臺創(chuàng)建臨時表
springboot 如何通過后臺創(chuàng)建臨時表
其實創(chuàng)建臨時表,跟增刪改查的原理是一樣的,只不過是在xml中寫一個創(chuàng)建臨時表sql語句,xml中并不是只能寫增刪改查語句的
1,首先弄一個xml
在xml中寫一個修改頭標簽,因為是建立的是臨時表,所以表名要變,需要在表名處接收一個參數(shù)$(tableName) ,這時xml文件就寫好了
2,在mapper中寫出對應方法
這時需要在參數(shù)中加上注解@Param,只有加上這個注解,在xml中才可以接收到我傳入的參數(shù)
3,接下來在service層和Controller層中調(diào)用這個方法
然后在postman中傳入需要的表名,就可以生成這個表了。
springboot mybatis下臨時表的創(chuàng)建和刪除,可用于查重去重
/** * 創(chuàng)建臨時表 */ @Update({"drop temporary table if exists ${tableName};", "create temporary table ${tableName} select doctor_id from crm_speaker where 1=2 "}) void createTemoraryTable(@Param("tableName") String tableName); /** * 保存數(shù)據(jù)到臨時表里面以便校驗數(shù)據(jù)重復 */ @Insert("<script>" + "insert into ${tableName} (doctor_id) values\n" + " <foreach collection=\"list\" item=\"doct\" index=\"index\" separator=\",\">\n" + " (" + " #{doct.doctorId,jdbcType=VARCHAR}\n" + " )\n" + " </foreach>\n" + "</script>") void insertBatchCheckDatas(@Param("list") List<SpeakerDO> dOs, @Param("tableName") String tableName); /** * 刪除臨時表 */ @Update({"drop temporary table if exists ${tableName}"}) void dropTemporaryTable(@Param("tableName") String tableName);
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
springboot?serviceImpl初始化注入對象實現(xiàn)方式
這篇文章主要介紹了springboot?serviceImpl初始化注入對象實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05Springboot+redis+Vue實現(xiàn)秒殺的項目實踐
本文主要介紹了Springboot+redis+Vue實現(xiàn)秒殺的項目實踐,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-08-08Java中Collections.emptyList()的注意事項
這篇文章主要給大家介紹了關于Java中Collections.emptyList()的注意事項,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-03-03