• 一个ibatis映射文件的例子(包含增删改单查,多查)


    
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.ZXC.lesson.dao.LessonUserDao">

    <sql id="table">
    user
    </sql>
    <sql id="insert_parm">
    u_id,u_name,u_sex,u_age
    </sql>
    <sql id="query_parm">
    u_id,u_name,u_sex,u_age,u_create_time,u_update_time
    </sql>


    <resultMap id="id" type="com.ZXC.lesson.model.LessonUser">
    <id column="u_id" property="ID"/>
    <result column="u_name" property="Name"/>
    <result column="u_sex" property="Sex"/>
    <result column="u_age" property="Age"/>
    </resultMap>

    <insert id="save" parameterType="com.ZXC.lesson.model.LessonUser"
    useGeneratedKeys="true" keyProperty="id">
    INSERT INTO <include refid="table"/>
    (<include refid="insert_parm"/>)
    VALUES
    (#{ID},#{Name},#{Sex},#{Age})
    </insert>

    <update id="update" parameterType="com.ZXC.lesson.model.LessonUser">
    UPDATE <include refid="table"/>
    <set>
    <if test="Sex!=null">u_sex=#{Sex}</if>
    <if test="Age!=null">u_age=#{age}</if>
    </set>
    </update>

    <update id="delete" parameterType="com.ZXC.lesson.model.LessonUser">
    UPDATE <include refid="table" />
    SET is_delete=1
    WHERE u_id=#{ID}
    </update>

    <select id="querybyid" parameterType="com.ZXC.lesson.model.LessonUser">
    SELECT <include refid="query_parm"/>
    FROM <include refid="table"/>
    WHERE u_id=#{ID} AND is_delete=0
    </select>

    <select id="querylist" parameterType="com.ZXC.lesson.model.LessonUser">
    SELECT <include refid="query_parm"/>
    FROM <include refid="table"/>
    WHERE id IN
    <foreach collection="uid_list" open="(" close=")" item="uid" separator=",">
           #{ID}
       </foreach>
    AND is_delete=0
    </select>
    </mapper>
     
  • 相关阅读:
    Android开发入门经典【申明:来源于网络】
    Java 的局部变量和成员变量
    js数组基础知识链接
    mongodb学习笔记2
    docker离线安装
    mongodb学习笔记
    jupyter notebook安装
    执行docker ps命令挂住问题分析
    keras安装简介(windows)
    mybatis查询日期和log4j2配置
  • 原文地址:https://www.cnblogs.com/television/p/9267391.html
Copyright © 2020-2023  润新知