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>
相关推荐
qq_424098563 分钟前
HTML5中解决数据库版本号管理混乱的规范化建议
jvm·数据库·python
Irene19918 分钟前
Python下载第三方库:requests、oracledb,连接 Oracle 数据库,测试数据输出(切记不要操作或删除系统表)
数据库·python·oracledb
四维迁跃12 分钟前
HTML5中SVG利用Javascript实现图形拖拽与缩放
jvm·数据库·python
我们的五年17 分钟前
mysql报错,net_async_status
数据库·mysql·adb
hINs IONN24 分钟前
在Mysql环境下对数据进行增删改查
数据库·mysql
Chuer_25 分钟前
AI For BI是什么?一文拆解AI For BI应用落地!
大数据·数据库·人工智能·安全·数据分析·甘特图
一颗青果30 分钟前
数据库事务
数据库·oracle
weixin_4249993631 分钟前
html如何修改备注
jvm·数据库·python
214396536 分钟前
HTML怎么创建时间轴布局_HTML结构化时间线写法【方法】
jvm·数据库·python
gmaajt37 分钟前
HTML函数开发需要SSD吗_SSD对HTML函数开发效率影响【详解】
jvm·数据库·python