zoukankan      html  css  js  c++  java
  • Java_myBatis_XML代理_动态SQL

    主要是设计到映射文件的编写:

    SELECT:

    <sql id="query_user_where">
        <!-- test里面可以编写OGNL表达式 -->
        <!-- 判断字符串不为空的标准写法 -->
        <if test=" user.username != null and user.username !='' ">
             AND username like '%${user.username}%'
        </if>
    </sql>
    
    <!-- 分页查询之查询记录 -->
    <select id="findUserList" parameterType="UserQueryVO"
        resultType="user">
        SELECT * FROM user
        <where>
            <include refid="query_user_where" />
        </where>
    </select>

    if语句前面必须带AND,where会自己判断什么时候该去除

    UPDATE:

    <update id="testDSQL" parameterType="User">
        UPDATE user 
        <set>
            <if test="username != null and username != ''">
                username = #{username},
            </if>
            <if test="address != null and address != ''">
                address = #{address},
            </if>
        </set>
        WERE id = 36
    </update>

    if最后的逗号是必须写的,set会自己判断什么时候去除

    INSERT:

    <insert id="insertSelective" parameterType="com.kkb.mybatis.pojo.Account" >
      <selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
        SELECT LAST_INSERT_ID()
      </selectKey>
      INSERT INTO account
      <trim prefix="(" suffix=")" suffixOverrides="," >
        <if test="name != null" >
          name,
        </if>
        <if test="money != null" >
          money,
        </if>
      </trim>
      <trim prefix="values (" suffix=")" suffixOverrides="," >
        <if test="name != null" >
          #{name,jdbcType=VARCHAR},
        </if>
        <if test="money != null" >
          #{money,jdbcType=DOUBLE},
        </if>
      </trim>
    </insert>

    if最后的逗号是必须写的,trim会自己判断什么时候去除

  • 相关阅读:
    liunx下忘记mysql的密码
    oracle add_month函数
    oracle的LAST_DAY()函数
    JAVA方法中参数到底是值传递还是引用传递
    list=null和list.size=0的区别
    对python 函数的一些理解
    python 文件流
    html canvas 简单体验
    angular js 指令
    初识 angular js
  • 原文地址:https://www.cnblogs.com/amiezhang/p/9615195.html
Copyright © 2011-2022 走看看