mybatis在工作中的使用简介

来源:互联网 发布:淘宝假发 编辑:程序博客网 时间:2024/05/18 16:35
<?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="tbl_xxxx">    <select id="selectAllDicts" parameterType="com.form.nokia.tbl_xxxx"        resultType="com.form.nokia.tbl_xxxx">        select * from tbl_xxxx t        <where>            <if test="key_seq != null and key_seq !='' ">                t.key_seq = #{key_seq}            </if>            <if test="key_type != null and key_type !='' ">                and t.key_type=#{key_type}            </if>            <if test="key_index != null and key_index !='' ">                AND t.key_index =#{key_index}            </if>        </where>    </select><!--根据指定的条件查询总数-->    <select id="selectCount" parameterType="com.form.nokia.tbl_xxxx"        resultType="java.lang.Integer">        select count(1) from tbl_xxxx t        <where>            <if test="key_seq != null and key_seq !='' ">                t.key_seq = #{key_seq}            </if>            <if test="key_type != null and key_type !='' ">                and t.key_type=#{key_type}            </if>            <if test="key_index != null and key_index !='' ">                AND t.key_index =#{key_index}            </if>        </where>    </select>    <select id="select" parameterType="com.form.nokia.tbl_xxxx"        resultType="com.form.nokia.tbl_xxxx">        <![CDATA[        SELECT tt.*,            d.dictvaluedesc as key_typedesc            FROM (        ]]>        SELECT * FROM (SELECT a.*,ROWNUM AS rn FROM (           select t.* from tbl_xxxx t            <where>                <if test="key_seq != null and key_seq !='' ">                t.key_seq = #{key_seq}            </if>            <if test="key_type != null and key_type !='' ">                and t.key_type=#{key_type}            </if>            <if test="key_index != null and key_index !='' ">                AND t.key_index =#{key_index}            </if>            </where>            <if test="sortString != null">                order by ${sortString}            </if>            ) a WHERE #{to} >=ROWNUM) b WHERE b.rn >= #{from}        ) tt        left join dictinfotb d on tt.key_type=d.dictvalue and d.dicttype=20018 and d.locale='zh_CN'                <if test="sortString != null">            order by ${sortString}        </if>    </select>   <!--添加一条记录-->    <insert id="insert" parameterType="com.form.nokia.tbl_xxxx">        insert into tbl_xxxx        <trim prefix="(" suffixOverrides=",">            <if test="key_seq          != null">key_seq          ,</if>              <if test="key_type         != null">key_type         ,</if>              <if test="key_usage        != null">key_usage        ,</if>              <if test="save_idex        != null">save_idex        ,</if>              <if test="key_index        != null">key_index        ,</if>              <if test="key_value        != null">key_value        ,</if>              <if test="pri_key          != null">pri_key          ,</if>              <if test="rsa_exp          != null">rsa_exp          ,</if>              <if test="key_chk          != null">key_chk          ,</if>              <if test="create_uid       != null">create_uid       ,</if>              <if test="create_time      != null">create_time      ,</if>              <if test="last_modify_uid  != null">last_modify_uid  ,</if>              <if test="last_modify_time != null">last_modify_time ,</if>      </trim>                  )                                values               <trim prefix="(" suffixOverrides=",">            <if test="key_seq          != null">#{key_seq          },</if>            <if test="key_type         != null">#{key_type         },</if>            <if test="key_usage        != null">#{key_usage        },</if>            <if test="save_idex        != null">#{save_idex        },</if>            <if test="key_index        != null">#{key_index        },</if>            <if test="key_value        != null">#{key_value        },</if>            <if test="pri_key          != null">#{pri_key          },</if>            <if test="rsa_exp          != null">#{rsa_exp          },</if>            <if test="key_chk          != null">#{key_chk          },</if>            <if test="create_uid       != null">#{create_uid       },</if>            <if test="create_time      != null">#{create_time      },</if>            <if test="last_modify_uid  != null">#{last_modify_uid  },</if>            <if test="last_modify_time != null">#{last_modify_time },</if>        </trim>        )    </insert>    <!--更新一条记录-->    <update id="update" parameterType="com.form.nokia.tbl_xxxx">        update tbl_xxxx        <set>            <if test="key_seq          != null">key_seq          =#{key_seq         },</if>            <if test="key_type         != null">key_type         =#{key_type        },</if>            <if test="key_usage        != null">key_usage        =#{key_usage       },</if>            <if test="save_idex        != null">save_idex        =#{save_idex       },</if>            <if test="key_index        != null">key_index        =#{key_index       },</if>            <if test="key_value        != null">key_value        =#{key_value       },</if>            <if test="pri_key          != null">pri_key          =#{pri_key         },</if>            <if test="rsa_exp          != null">rsa_exp          =#{rsa_exp         },</if>            <if test="key_chk          != null">key_chk          =#{key_chk         },</if>            <if test="create_uid       != null">create_uid       =#{create_uid      },</if>            <if test="create_time      != null">create_time      =#{create_time     },</if>            <if test="last_modify_uid  != null">last_modify_uid  =#{last_modify_uid },</if>            <if test="last_modify_time != null">last_modify_time =#{last_modify_time},</if>        </set>        where key_seq=#{key_seq}    </update>  <!--删除一条记录-->    <delete id="delete" parameterType="com.form.nokia.tbl_xxxx">        delete from tbl_xxxx        where key_seq=#{key_seq} and key_type=#{key_type}    </delete></mapper>


1.以上是mybatis的增删改查:工作中常用到的。




0 0
原创粉丝点击