zoukankan      html  css  js  c++  java
  • MyBatis动态sql语句归纳

    1.删除数据(假删除)并修改时间

    <!--根据id删除学生信息(多条)-->
    <update id="updateStuStatus" parameterType="map">
        UPDATE student_t
        SET status = 0, modifiy_time = #{modifiyTime,jdbcType=TIMESTAMP}
        WHERE _id in(
          <foreach collection="list" item="id" separator=",">
            #{id, jdbcType=INTEGER}
          </foreach>
        )
    </update>

    传入的数据:

    //Service
    Map<String,Object> map = new HashMap<String,Object>();
    map.put("list",list);
    map.put("modifiyTime",date);
    int result = studentInfoEntityMapper.updateStuStatus(map);

     2.根据学生id查找学生图片

    <!--查询学生图片-->
    <select id="selectByStuList" resultMap="BaseResultMap">
        SELECT  img_src
        FROM img_t
        WHERE
        stu_id IN
        <foreach collection="list" item="item" open="(" separator="," close=")">
          #{item.id,jdbcType=INTEGER}
        </foreach>
        and status = 1
        ORDER BY create_time DESC
    </select>
    
    <!--传入的数据,dao层-->
    List<ImgInfoEntity> selectByStuList(List<StudentInfoEntity> list);

    3.根据教师id查找学生信息,或者根据学生名字查找学生信息

    <!--根據教師id,查询學生信息。或者,根據學生姓名,查詢學生信息-->
    <select id="selectStuAllByTeaId" parameterType="map" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM student_t
        <where>
        <if test="list != null">
          AND tea_id IN
          <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item.id}
          </foreach>
        </if>
        <if test="name != null">
          AND name LIKE  '%${name}%'
        </if>
        AND status = 1
        </where>
        ORDER BY create_time DESC
    </select>
    
    <!--方式二:--> <select id="selectStuAllByTeaId" parameterType="java.util.Map" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from student_t <where> <if test="_parameter.containsKey('list')"> AND tea_id IN <foreach collection="list" item="item" open="(" separator="," close=")"> #{item.id} </foreach> </if> <if test="_parameter.containsKey('name')"> AND name LIKE '%${name}%' </if> </where> order by create_time DESC </select>
  • 相关阅读:
    bat %n 判断传入的参数值和使用注意
    git ls-remote url,判断 url 是否存在
    bat 读取 ini 文件
    bat 提示窗口,带换行
    python .pth 文件 和 site 模块
    python Pillow 图片处理模块,好强大有没有
    Python 获取 exe 的 icon 并且保存
    git 判断路径是否是 git 仓库
    Python 去除字符串中的空行
    Android平台程序崩溃的类型及原因列举
  • 原文地址:https://www.cnblogs.com/nananana/p/8599347.html
Copyright © 2011-2022 走看看