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);
以上就是springboot中怎么实现通过后台创建临时表的详细内容。