• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

springboot中实现通过后台创建临时表

springboot 搞代码 4年前 (2022-01-09) 25次浏览 已收录 0个评论
文章目录[隐藏]

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\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 ${<i>本文来源gaodai$ma#com搞$$代**码)网@</i>tableName}"})
    void dropTemporaryTable(@Param("tableName") String tableName);

以上为个人经验,希望能给大家一个参考,也希望大家多多支持搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:springboot中实现通过后台创建临时表
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址