Mybites基础篇(一)--增删改查(实用)

1.增

<insert id="insert" parameterType="com.itheima.cn.Student"> 
    <selectKey keyProperty="id" resultType="String" order="BEFORE">SELECT REPLACE(NEWID(),'-','')</selectKey> 
    INSERT INTO student (stuId,stuName,createDate,birthday)
    VALUES
    ( #{id,jdbcType=VARCHAR},#{stuName,jdbcType=VARCHAR},
    {createDate,jdbcType=DATE}, #{birthday,jdbcType=TIMESTAMP})
  </insert> 

2.删

<delete id="delete">DELETE FROM student WHERE ID IN 
    <foreach 
      item="stuId" collection="list" open="(" separator="," close=")">
    #{stuId,jdbcType=VARCHAR}
    </foreach> 
  </delete> 

3.改

<update id="update" parameterType="com.itheima.cn.Student">UPDATE student
    <set> 
      <if test="stuId!= null">stuId=#{stuId,jdbcType=VARCHAR},</if>
      <if test="stuName!= null">stuName=#{stuName,jdbcType=VARCHAR},</if>
      <if test="createDate!= null">createDate=#{createDate,jdbcType=DATE},</if>
      <if test="birthday!= null">birthday=#{birthday,jdbcType=TIMESTAMP}</if>
    </set> WHERE ID=#{id}
  </update>

4.基本查询

<resultMap id="student" type="com.itheima.cn.Student"> 
    <id property="stuId" column="stuId"/>  
    <result property="stuName" column="stuName"/>  
    <result property="createDate" column="createDate"/>  
  </resultMap>  
<select id="list" resultMap="student" parameterType="map">
	  SELECT stuId,stuName,createDate,birthday FROM student
    <where> 
     <if test="stuId!= null and stuId!=''">AND stuId LIKE  '%'+#{stuId}+'%'</if>
      <if test="stuName!= null and stuName!=''">AND stuName LIKE  '%'+#{stuName}+'%'</if>  
       <if test="ids!= null and ids!=''">AND stuId  in
			<foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
                #{id}       
        </foreach>
		</if>
    </where> 
  </select> 

笔记一

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值