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_444012932 分钟前
CSS定位如何实现模态框垂直居中_使用负边距或transform
jvm·数据库·python
2301_783848656 分钟前
Go 中实现高效图最大团划分的实践与边界分析
jvm·数据库·python
2401_884454157 分钟前
C#怎么实现Socket心跳包 C#如何在TCP Socket通信中设计心跳机制检测连接状态【网络】
jvm·数据库·python
Jetev20 分钟前
不同品牌SSD对HTML函数工具加载速度影响大吗_存储测试汇总【汇总】
jvm·数据库·python
SelectDB技术团队20 分钟前
时间序列近邻关联性能实测:Doris ASOF JOIN 领先 ClickHouse、DuckDB
数据库·人工智能·selectdb
Traving Yu38 分钟前
向量数据库Milvus
数据库·人工智能·milvus
2501_9010064742 分钟前
golang如何使用DTM分布式事务框架_golang DTM分布式事务框架使用方法
jvm·数据库·python
2501_901200531 小时前
Golang如何做Clean Architecture_Golang整洁架构教程【详解】
jvm·数据库·python
咖啡里的茶i1 小时前
实验三 数据完整性实验
数据库·oracle
韶博雅1 小时前
oracle + parfile(数据泵)
数据库·oracle