zoukankan      html  css  js  c++  java
  • 学习Mybatis xml 常用关键语法 Ivin

    1.<where>和<if>

    <!-- 根据条件查询用户 -->
    <select id="queryUserByWhere" parameterType="user" resultType="user">
        SELECT id, username, birthday, sex, address FROM `user`
        WHERE 1=1
        <if test="sex != null and sex != ''">
            AND sex = #{sex}
        </if>
        <if test="username != null and username != ''">
            AND username LIKE
            '%${username}%'
        </if>
    </select>

    if 内部判断的是传递过来的实体参数中的字段,判断参数字段内容,如果为ture 执行if 内部命令

    2.<include refid> 个人认为为标签索引

        <sql id="Base_Column_List" >
                collegeID, collegeName
        </sql> 
         
        <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
               select 
                <include refid="Base_Column_List" />
                from t_notification_template
               where id = #{id,jdbcType=BIGINT}
         </select>

    内部select查询中可以使用索引标签

    好处是将公共部分提出来,方便后续开发使用。

    4.<foreach>   参数为list时,可使用

    <select id="countByUserList" resultType="_int" parameterType="list">
    select count(*) from users
      <where>
        id in
        <foreach item="item" collection="list" separator="," open="(" close=")" index="">
          #{item.id, jdbcType=NUMERIC}
        </foreach>
      </where>
    </select>
  • 相关阅读:
    ZYNQ xilinx之困惑
    位操作的宏函数实现
    BCG信号的检测【时时更新】
    课题兼申请任务Freescale的K60系列
    SDRAM之持续中。。。。。。
    几款常见的免费网站程序
    常用运放选型
    SDRAM之开始burst length
    谈 数学之美 和 看见
    C语言中的可变参数(...)
  • 原文地址:https://www.cnblogs.com/ivin/p/13672530.html
Copyright © 2011-2022 走看看