• mybatis XML SQL基本配置



    <!--分页参数查询-->
    <select id="findByPage1" resultType="user">
        select * from t_user limit #{startIndex},#{pageSize}
    </select>
    <!--分页参数查询-->
    <select id="findByPage2" resultType="user">
        select * from t_user limit #{param1},#{param2}
    </select>
    
    
    <!--多条件查询QueryVO封装条件-->
    <select id="findByQueryVO" resultType="user">
        select * from t_user
        where user_name like concat("%",#{user.username},"%") and sex = #{user.sex}
        limit #{startIndex},#{pageSize}
    </select>
    <!--多条件查询Map封住条件-->
    <select id="findByMap" resultType="user">
        select * from t_user
        where user_name like concat("%",#{username},"%") and sex = #{sex}
        limit #{startIndex},#{pageSize}
    </select>
    <select id="selectAll" resultMap="userResultMap">
        select * from t_user
    </select>
    <!--回显主键-->
    <!--  第一种int类型
        keyColumn:主键字段名
        keyProperty:主键属性名
        resultType:属性类型
        order:执行时机
                可选择:AFTER,BEFORE 只能写大写
        select last_insert_id():查询最后一次新增的id
    -->
    <insert id="insert01">
      <selectKey keyColumn="id" keyProperty="id" resultType="int" order="AFTER">
          /*查询最后一次新增的id  并封装到user里面*/
        select last_insert_id()
      </selectKey>
        INSERT INTO `t_user` (
            `id`,
            `user_name`,
            `birthday`,
            `sex`,
            `home_address`
            )
        VALUES
          (
            null,
            #{username},
            #{birthday},
            #{sex},
            #{address}
          )
    </insert>
    
    <!--第二种获取主键方式int类型  是否自动回显主键-->
    <insert id="insert02" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
        INSERT INTO `t_user` (
        `id`,
        `user_name`,
        `birthday`,
        `sex`,
        `home_address`
        )
        VALUES
        (
        null,
        #{username},
        #{birthday},
        #{sex},
        #{address}
        )
    </insert>
    <!--  第三种String类型
    keyColumn:主键字段名
    keyProperty:主键属性名
    resultType:属性类型
    order:执行时机
            可选择:AFTER,BEFORE 只能写大写
    select last_insert_id():查询最后一次新增的id
    

    -->


    /查询最后一次新增的id 并封装到user里面/
    select uuid()/自己生成一个传递过去/

    INSERT INTO t_user (
    id,
    user_name,
    birthday,
    sex,
    home_address
    )
    VALUES
    (
    null,
    #{username},
    #{birthday},
    #{sex},
    #{address}
    )

  • 相关阅读:
    Java经典逻辑编程50题 (转)
    Programmingbydoing
    前端测试框架jest 简介
    puppeteer入门
    面向对象编程
    Java常识
    JS 变量
    jmeter 压力测试
    jmeter 安装
    Java 数据驱动测试
  • 原文地址:https://www.cnblogs.com/x-i-n/p/14111086.html
Copyright © 2020-2023  润新知