MyBatis中XML文件的模板

MyBatis中XML文件的模板

xml 复制代码
<?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="generator.mapper.UsersMapper">

    <resultMap id="BaseResultMap" type="generator.domain.Users">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="username" column="username" jdbcType="VARCHAR"/>
            <result property="password" column="password" jdbcType="VARCHAR"/>
            <result property="email" column="email" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,username,password,
        email
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from users
        where  id = #{id,jdbcType=INTEGER} 
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from users
        where  id = #{id,jdbcType=INTEGER} 
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="generator.domain.Users" useGeneratedKeys="true">
        insert into users
        ( id,username,password
        ,email)
        values (#{id,jdbcType=INTEGER},#{username,jdbcType=VARCHAR},#{password,jdbcType=VARCHAR}
        ,#{email,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="generator.domain.Users" useGeneratedKeys="true">
        insert into users
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="username != null">username,</if>
                <if test="password != null">password,</if>
                <if test="email != null">email,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="id != null">#{id,jdbcType=INTEGER},</if>
                <if test="username != null">#{username,jdbcType=VARCHAR},</if>
                <if test="password != null">#{password,jdbcType=VARCHAR},</if>
                <if test="email != null">#{email,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="generator.domain.Users">
        update users
        <set>
                <if test="username != null">
                    username = #{username,jdbcType=VARCHAR},
                </if>
                <if test="password != null">
                    password = #{password,jdbcType=VARCHAR},
                </if>
                <if test="email != null">
                    email = #{email,jdbcType=VARCHAR},
                </if>
        </set>
        where   id = #{id,jdbcType=INTEGER} 
    </update>
    <update id="updateByPrimaryKey" parameterType="generator.domain.Users">
        update users
        set 
            username =  #{username,jdbcType=VARCHAR},
            password =  #{password,jdbcType=VARCHAR},
            email =  #{email,jdbcType=VARCHAR}
        where   id = #{id,jdbcType=INTEGER} 
    </update>
</mapper>
相关推荐
weixin_468466854 小时前
Airtable 零基础快速上手与实战指南
数据库·人工智能·python·深度学习·ai·大模型
凯瑟琳.奥古斯特4 小时前
10道数据库原理精选题
开发语言·数据库·职场和发展·数据库开发
Rick19934 小时前
Redis 高频面试 10 题
数据库·redis·面试
陈橘又青4 小时前
国产数据库工具测评:DBLens 以本地化工程能力与 AI 演进路径凸显优势
数据库
念恒123064 小时前
MySQL事务(下)---MySQL InnoDB MVCC 与 Read View:从隐藏列、Undo Log 到 RR 与 RC 的本质区别
数据库·mysql·oracle
i220818 Faiz Ul4 小时前
在线预约导游|基于SSM+vue的在线预约导游系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·毕设·在线预约导游系统
anew___4 小时前
《数据库原理》精要解读(五)—— 数据库完整性:守护数据的真实与逻辑
数据库·oracle
Java面试题总结4 小时前
MySQL EXISTS 详解:存在性判断、NOT EXISTS 与实战示例
android·数据库·mysql
cuijiecheng20184 小时前
Little-Anti-Cheat源码分析(1)——Little-Anti-Cheat插件简介
数据库
土狗TuGou4 小时前
SQL内功笔记 · 第5篇:SQL逻辑执行顺序
数据库·笔记·后端·sql·mysql