Java tatsächlicher Combat_trim in Mapper.xml

 

Attribut trimmen
                Präfix: Das Präfix überschreibt und erhöht seinen Inhalt.
                Suffix: Das Suffix überschreibt und erhöht seinen Inhalt.
                prefixOverrides: die Bedingung für die Präfixbeurteilung.
                suffixOverrides: die Bedingung für die Suffixbeurteilung

 <update id="updateTest" >
        UPDATE test 
        <trim prefix="SET" suffixOverrides=",">
         <if test="name!=null and name!=‘‘">
         name = #{name},
         </if>
         <if test="phone!=null and phone!=‘‘">
         phone = #{phone},
         </if>
         <if test="address!=null and address!=‘‘">
         address = #{address},
         </if>
       </trim>  
        WHERE 
         id = #{id} 
 </update>

输出SQL-
Update-Testsatz Name = #{Name}, Telefon = #{Telefon}, Adresse = #{Adresse} WHERE id = #{id}

<select id="checkUserByPhone" parameterType="User" resultMap="UserMap">
  select * from user
  <trim prefix="WHERE" prefixOverrides="AND | OR">
   <if test="userId!=null and userId!=‘‘">
         and user_id != #{userId}
         </if>
   <if test="phone!=null and phone!=‘‘ and state!=‘All‘">
         and phone = #{phone} and state!=‘X‘
         </if>
           
  </trim>
 </select>

 

SQL-Ausgabe 

  select * from user WHERE user_id != #{userId} and phone = #{phone} and state!='X'  

Guess you like

Origin blog.csdn.net/qq_41916378/article/details/108265311