Home  >  Article  >  Java  >  How to create a temporary table through the background in springboot

How to create a temporary table through the background in springboot

王林
王林forward
2023-05-19 22:50:201909browse

springboot How to create a temporary table through the background

In fact, creating a temporary table is the same as the principle of adding, deleting, modifying, and querying. It is just writing a create temporary table sql statement in xml. There is not only If you can write add, delete, modify, query statements,

1, first make an xml

and write a modification header tag in the xml. Because a temporary table is created, the table name needs to be changed. The table name receives a parameter $(tableName). At this time, the xml file is written

How to create a temporary table through the background in springboot

2. Write the corresponding method in the mapper

This When you need to add the annotation @Param to the parameter, only by adding this annotation can you receive the parameters I passed in in xml

How to create a temporary table through the background in springboot

3, and then in the service Call this method

in the layer and Controller layer and then pass in the required table name in postman to generate this table.

The creation and deletion of temporary tables under springboot mybatis can be used for duplication checking and deduplication

/**
     * 创建临时表
     */
    @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);

The above is the detailed content of How to create a temporary table through the background in springboot. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete