mybatis的sql语句

在xml文件中写sql语句
如 查询语句需要写

<select id="checkCutomExist" parameterType="com.oracle.entitys.Custom" resultType="String">
        select name from Custom where phoneNo = #{phoneNo} and email=#{email}
    </select>

这里查询语句需要写select标签 其中

  1. id 必须要和调用的方法对应 大小写敏感
  2. parameterType 代表着 你要传入的数据类型 所在的具体类的地址
  3. parameterMap 是你之前定义的resultMap标签id
<resultMap id="BaseResultMap" type="com.oracle.entitys.Custom">
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="name" property="name" jdbcType="CHAR" />
        <result column="education" property="education" jdbcType="CHAR" />
        <result column="phoneNo" property="phoneNo" jdbcType="CHAR" />
        <result column="qq" property="qq" jdbcType="CHAR" />
        <result column="email" property="email" jdbcType="CHAR" />
        <result column="customStatu" property="customStatu" jdbcType="CHAR" />
        <result column="createDate" property="createDate" javaType="java.sql.Date" />
        <result column="inviteName" property="inviteName" jdbcType="CHAR" />
    </resultMap>
  1. resultType是你要返回的数据类型,基本类型可以直接写resultType=“基本类型和String”
  2. resultMap和之前的parameterMap 方式一样
  3. 其中批量插入不需要写useGeneratedKeys和keyProperty
  4. 插入语句
    <insert id="insertSelective" parameterType="com.oracle.entitys.Custom" useGeneratedKeys="true"
        keyProperty="id">

useGeneratedKeys把新增加的主键赋值到自己定义的keyProperty(id)中

  • 更新语句
    • if条件语句
<update id="updateByPrimaryKeySelective" parameterType="com.oracle.entitys.Custom">
        update custom <set>
    <if test="name !=null"> name = #{name},</if> 
    <if test="education !=null"> education = #{education},</if> 
    <if test="phoneNo !=null"> phoneNo = #{phoneNo},</if> 
    <if test="qq !=null"> qq = #{qq},</if> 
    <if test="email !=null"> email = #{email},</if> 
    <if test="customStatu !=0"> customStatu = #{customStatu},</if> 
    </set>
     where id = #{id}
    </update>
  • 删除语句
<delete id="deleteCstomIfos" parameterType="java.util.List">
        delete from customInfo where customId in (
        <foreach collection="list" item="item" index="index"
            separator=";">
            #{item}
        </foreach>
        )

    </delete>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值