springboot 如何通过后台创建临时表
其实创建临时表,跟增删改查的原理是一样的,只不过是在xml中写一个创建临时表sql语句,xml中并不是只能写增删改查语句的
1,首先弄一个xml
在xml中写一个修改头标签,因为是建立的是临时表,所以表名要变,需要在表名处接收一个参数$(tableName) ,这时xml文件就写好了
2,在mapper中写出对应方法
这时需要在参数中加上注解@Param,只有加上这个注解,在xml中才可以接收到我传入的参数
3,接下来在service层和Controller层中调用这个方法
然后在postman中传入需要的表名,就可以生成这个表了。
springboot mybatis下临时表的创建和删除,可用于查重去重
/**
* 创建临时表
*/
@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);
/**
* 保存数据到临时表里面以便校验数据重复
*/
@Insert("<script>" +
"insert into ${tableName} (doctor_id) values
" +
" <foreach collection="list" item="doct" index="index" separator=",">
" +
" (" +
" #{doct.doctorId,jdbcType=VARCHAR}
" +
" )
" +
" </foreach>
" +
"</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);
以上为个人经验,希望能给大家一个参考,也希望大家多多支持快网idc。
原文链接:https://blog.csdn.net/qq_39776207/article/details/80627918
相关文章
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10



