mybatis xml sql 语句的常用语句

 

 

官网:https://mybatis.net.cn/dynamic-sql.html

 

 

1:提取公共的sql语句:

mybatis xml sql 语句的常用语句

 

2:动态添加----sql语句:

mybatis xml sql 语句的常用语句mybatis xml sql 语句的常用语句

代码:

mybatis xml sql 语句的常用语句
  <insert >
        INSERT INTO product
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productName!=null and productName!=''">
                product_name,
            </if>
            <if test="stockNum!=null and stockNum!=''">
                stock_num,
            </if>
            <if test="salePrice!=null and salePrice!=''">
                sale_price,
            </if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="productName!=null and productName!=''">
                #{productName},
            </if>
            <if test="stockNum!=null and stockNum!=''">
                #{stockNum},
            </if>
            <if test="salePrice!=null and salePrice!=''">
                #{salePrice},
            </if>

        </trim>
    </insert>
View Code

相关文章: