mybatis 的動態標簽之一update And insert示例


一動態標簽之update

update 基礎語法

UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

trim 標簽中各個元素的含義

prefix:在trim標簽內sql語句加上前綴。
suffix:在trim標簽內sql語句加上后綴。
prefixOverrides:指定去除多余的前綴內容
suffixOverrides:指定去除多余的后綴內容,如:suffixOverrides=",",去除trim標簽內sql語句多余的后綴","。

動態標簽紙更新表-》方式一使用update 注解

動態標簽紙更新表-》方式二使用update 標簽方式

二動態標簽之insert插入語法

語句基礎語法
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);```

##2.1:insert動態插入之insert 標簽
<insert id="insertTable" parameterType = "tableDao">
  INSERT INTO tableDaoa  
  <trim prefix="(" suffix=")" suffixOverrides=",">
                  <if test="id!=null"> id, </if> 
                  <if test="time!=null"> time, </if>
            </trim>
            VALUES
            <trim prefix="(" suffix=")" suffixOverrides=",">
                  <if test="id!=null"> #{id}, </if> 
                  <if test="time!=null"> #{time}, </if>
            </trim>
  </insert>
#:2.2:insert插入之insert注解
   @Insert({"<script>" +
            "insert into dataBseTable" +
            "   <trim prefix='(' suffix=')' suffixOverrides=','> " +
            "      <if test='type != null'> " +
            "        `type`, " +
            "      </if> " +
            "      <if test='dbName != null'> " +
            "        db_name, " +
            "      </if> " +
            "    </trim> " +
            "    <trim prefix='values (' suffix=')' suffixOverrides=','> " +
            "      <if test='type != null'> " +
            "        #{type,jdbcType=INTEGER}, " +
            "      </if> " +
            "      <if test='dbName != null'> " +
            "        #{dbName,jdbcType=VARCHAR}, " +
            "      </if> " +
            "    </trim>" +
            "</script>"})
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insertSelective(Data do);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM