MyBatis中XML 映射配置文件的简单介绍
MyBatis中XML 映射配置文件的简单介绍
乐在克里特 发表于11个月前
MyBatis中XML 映射配置文件的简单介绍
  • 发表于 11个月前
  • 阅读 3
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

官网写的比较具体,可以查看以下的网站:

http://www.mybatis.org/mybatis-3/zh/configuration.html

 

另外,实际用到标准的CRUD的操作和查询列表,

<?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.iteye.tom.dao.AuthItemRecordDao">
    
    <sql id="requestAllFields">
        <![CDATA[
            id,
            record_time AS recordTime,
            source_code AS sourceCode,
            userid,
            auth_item_id AS authItemId,
            isvalid,
            last_status_time AS lastStatusTime
        ]]>
    </sql>
    
    <sql id="whereClause">
        <where>
            <if test="null!=id">AND id = #{id}</if>
            <if test="null!=sourceCode and ''!=sourceCode">AND source_code = #{sourceCode}</if>
            <if test="null!=userid and ''!=userid">AND userid = #{userid}</if>
            <if test="null!=authItemId and ''!=authItemId">AND auth_item_id = #{authItemId}</if>
            <if test="null!=isvalid and ''!=isvalid">AND isvalid = #{isvalid}</if>
            <include refid="extendedWhereClause" />
        </where>
    </sql>
    
    <insert id="add" useGeneratedKeys="true" parameterType="com.iteye.tom.bean.AuthItemRecord" keyProperty="id">
        INSERT INTO tab_auth_item_record
        <trim prefix="(" suffix=")" prefixOverrides=",">
            <if test="null!=recordTime">,record_time</if>
            <if test="null!=sourceCode and ''!=sourceCode">,source_code</if>
            <if test="null!=userid and ''!=userid">,userid</if>
            <if test="null!=authItemId and ''!=authItemId">,auth_item_id</if>
            <if test="null!=isvalid and ''!=isvalid">,isvalid</if>
            <if test="null!=lastStatusTime">,last_status_time</if>
        </trim>
        VALUES
        <trim prefix="(" suffix=")" prefixOverrides=",">
            <if test="null!=recordTime">,#{recordTime}</if>
            <if test="null!=sourceCode and ''!=sourceCode">,#{sourceCode}</if>
            <if test="null!=userid and ''!=userid">,#{userid}</if>
            <if test="null!=authItemId and ''!=authItemId">,#{authItemId}</if>
            <if test="null!=isvalid and ''!=isvalid">,#{isvalid}</if>
            <if test="null!=lastStatusTime">,#{lastStatusTime}</if>
        </trim>
    </insert>
    
    <update id="update" parameterType="com.iteye.tom.bean.AuthItemRecord">
        UPDATE tab_auth_item_record
        <trim prefix="SET" prefixOverrides=",">
            <if test="null!=recordTime">,record_time = #{recordTime}</if>
            <if test="null!=sourceCode and ''!=sourceCode">,source_code = #{sourceCode}</if>
            <if test="null!=userid and ''!=userid">,userid = #{userid}</if>
            <if test="null!=authItemId and ''!=authItemId">,auth_item_id = #{authItemId}</if>
            <if test="null!=isvalid and ''!=isvalid">,isvalid = #{isvalid}</if>
            <if test="null!=lastStatusTime">,last_status_time = #{lastStatusTime}</if>
            <include refid="extendedUpdateSql" />
        </trim>
        WHERE id = #{id}
    </update>
    
    <select id="query" parameterType="com.iteye.tom.bean.AuthItemRecord" resultType="com.iteye.tom.bean.AuthItemRecord">
        SELECT <include refid="requestAllFields"/> FROM tab_auth_item_record
        <include refid="whereClause" />
        <include refid="extendedOrderByClause" />
        <if test="null!=requestOffset">
            LIMIT #{requestOffset}, #{requestCount}
        </if>
    </select>
    
    <select id="get" parameterType="com.iteye.tom.bean.AuthItemRecord" resultType="com.iteye.tom.bean.AuthItemRecord">
        SELECT <include refid="requestAllFields"/> FROM tab_auth_item_record
        <include refid="whereClause" />
        LIMIT 1
    </select>
    
    <select id="getById" parameterType="long" resultType="com.iteye.tom.bean.AuthItemRecord">
        SELECT <include refid="requestAllFields"/> FROM tab_auth_item_record WHERE id = #{id}
    </select>
    
    <select id="count" parameterType="com.iteye.tom.bean.AuthItemRecord" resultType="int">
        SELECT COUNT(1) FROM tab_auth_item_record <include refid="whereClause" />
    </select>

    <delete id="deleteByUserid" parameterType="com.iteye.tom.bean.AuthItemRecord" >
        DELETE FROM tab_auth_item_record WHERE userid = #{userid}    </delete>
    
    <!-- 扩展的更新等语句(自定义)-->
    <sql id="extendedUpdateSql">
        <if test="null!=extendedParameter">
            
        </if>
    </sql>
    
    <!-- 扩展的条件过滤语句(自定义)-->
    <sql id="extendedWhereClause">
        <if test="null!=extendedParameter">
            
        </if>
    </sql>
    
    <!-- 扩展的排序等语句(自定义)-->
    <sql id="extendedOrderByClause">
        <if test="null!=extendedParameter">
            
        </if>
    </sql>
</mapper>

 

标签: MyBatis
共有 人打赏支持
粉丝 14
博文 254
码字总数 387498
×
乐在克里特
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: