• MyBatis中XML 映射配置文件的简单介绍


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

    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>
  • 相关阅读:
    站点被百度惩处应从哪些方面分析
    SVN 权限配置具体说明
    关于数组的应用
    实现键值对存储(二)——以现有键值对存储为模型
    大数据Lambda架构
    关于c++primer的一个代码错误
    怎样解决Ubuntu发热严重地问题
    【maven】pom.xml文件没错,但是项目有小红叉,Problems中可以看到错误:“Dynamic Web Module 3.0 requires Java 1.6 or newer.”
    【shiro】2.spring整合shiro,注解控制shiro用户/角色/权限And/OR,没有权限跳转到固定页面
    【shiro】使用shiro搭建的项目,页面引用js,报错:Uncaught SyntaxError: Unexpected token <
  • 原文地址:https://www.cnblogs.com/itommy/p/10610364.html
Copyright © 2020-2023  润新知