mybatis中的基本sql书写

本文详细介绍了MyBatis框架中四种基本的SQL操作:查询、插入、修改和删除,涵盖各个操作的核心语法和使用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


查询语句

 <!--返回Map-->        
    <resultMap id="BaseResultMap" type="com.rongdu.cashloan.rule.domain.RuleInfo">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="tb_nid" property="tbNid" jdbcType="VARCHAR" />
        <result column="tb_name" property="tbName" jdbcType="VARCHAR" />
        <result column="detail" property="detail" jdbcType="VARCHAR" />
        <result column="state" property="state" jdbcType="VARCHAR" />
        <result column="req_ext" property="reqExt" jdbcType="VARCHAR" />
        <result column="add_time" property="addTime" jdbcType="TIMESTAMP" />
    </resultMap>


 <!--基本的sql查询字段 公共引用...-->
    <sql id="Base_Column_List">
        id,tb_nid,tb_name,detail,state,req_ext,add_time 
    </sql>


<!-- 基本的sql查询条件公共引用 -->
    <sql id="searchBy">
        <trim prefix="where" prefixOverrides="and|or">
            <if test="id !='' and id !=null">
                id  = #{id,jdbcType=BIGINT}
            </if>
            <if test="tbNid !='' and tbNid !=null">
                and tb_nid like CONCAT("%",#{tbNid,jdbcType=VARCHAR},"%")
            </if>
            <if test="tbName !='' and tbName !=null">
                and tb_name like CONCAT("%",#{tbName,jdbcType=VARCHAR},"%") 
            </if>
            <if test="detail !='' and detail !=null">
                and detail = #{detail,jdbcType=VARCHAR}
            </if>
            <if test="state !='' and state !=null">
                and state = #{state,jdbcType=VARCHAR}
            </if>
            <if test="reqExt !='' and reqExt !=null">
                and req_ext = #{reqExt,jdbcType=VARCHAR}
            </if>
            <if test="addTime !=null">
                and add_time = #{addTime,jdbcType=TIMESTAMP}
            </if>
        </trim>
    </sql>

    <!--查询语句-->
      <select id="listSelective" resultMap="BaseResultMap" parameterType="java.util.HashMap">
        select
        <include refid="Base_Column_List" />
        from arc_rule_info
        <include refid="searchBy"/> order  by  state  asc,add_time desc
    </select>

插入语句

<insert id="save" parameterType="com.rongdu.cashloan.rule.domain.RuleInfo">
        insert into arc_rule_info(tb_nid,tb_name,detail,state,req_ext,add_time )values(#{tbNid,jdbcType=VARCHAR},#{tbName,jdbcType=VARCHAR},#{detail,jdbcType=VARCHAR},#{state,jdbcType=VARCHAR},#{reqExt,jdbcType=VARCHAR}, #{addTime,jdbcType=TIMESTAMP})
    </insert>

修改语句

  <update id="update" parameterType="com.rongdu.cashloan.rule.domain.RuleInfo">
        update arc_rule_info set 
            tb_nid = #{tbNid,jdbcType=VARCHAR},
            tb_name = #{tbName,jdbcType=VARCHAR},
            detail = #{detail,jdbcType=VARCHAR},
            state = #{state,jdbcType=VARCHAR},
            req_ext = #{reqExt,jdbcType=VARCHAR},
            add_time = #{addTime,jdbcType=TIMESTAMP}
        where id = #{id ,jdbcType=BIGINT}
    </update>

删除语句

  <delete id="delInfoById"  parameterType="java.util.HashMap">
        delete   from arc_rule_info  where id = #{id,jdbcType=BIGINT}
    </delete>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值