您的位置:首页 > 其它

mybatis 总结

2016-07-24 12:50 323 查看
<resultMap id="blogMap" type="Blog" >

      <id column="id" property="id" jdbcType="INTEGER" />

      <result column="title" property="title" jdbcType="VARCHAR" />

      <result column="content" property="content" jdbcType="VARCHAR" />

   </resultMap>

   <sql id="bloglist" >

     id, title, content

   </sql>

 1 select  

<select id="selectById" resultMap="blogMap" parameterType="java.lang.Integer" >

     select 

     <include refid="bloglist" />

     from blog

     where id = #{id}

   </select>

 2 delete

   <delete id="deleteById" parameterType="java.lang.Integer" >

     delete from blog

     where id = #{id,jdbcType=INTEGER}

   </delete>

 3 insert

   <insert id="insert" parameterType="blog" >

     insert into blog(id, title,  content)

     values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR})

   </insert>

   <insert id="insertSelective" parameterType="blog" >

     insert into blog

     <trim prefix="(" suffix=")" suffixOverrides="," >

       <if test="id != null" >

         id,

       </if>

       <if test="title != null" >

         title,

       </if>

       <if test="describe != null" >

         describe,

       </if>

       <if test="content != null" >

         content,

       </if>

     </trim>

     <trim prefix="values (" suffix=")" suffixOverrides="," >

       <if test="id != null" >

         #{id,jdbcType=INTEGER},

       </if>

       <if test="title != null" >

         #{title,jdbcType=VARCHAR},

       </if>

       <if test="content != null" >

         #{content,jdbcType=VARCHAR},

       </if>

     </trim>

   </insert>

 4 update

   <update id="updateByIdSelective" parameterType="blog" >

     update blog

     <set >

       <if test="title != null" >

         title = #{title,jdbcType=VARCHAR},

       </if>

       <if test="content != null" >

         content = #{content,jdbcType=VARCHAR},

       </if>

     </set>

     where id = #{id,jdbcType=INTEGER}

   </update>

  5 update

 <update id="updateByID" parameterType="blog" >

     update blog

     set title = #{title,jdbcType=VARCHAR},

       content = #{content,jdbcType=VARCHAR}

     where id = #{id,jdbcType=INTEGER}

   </update>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mybatis3