Home > Java > javaTutorial > body text

How to create a temporary table through the background in springboot

王林
Release: 2023-05-19 22:50:20
forward
1945 people have browsed it

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);
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template