mybatis 入门xml

<mapper namespace="com.qq.mapper.BookMapper">
    <select id="selectAll" resultType="Book">
    select * from book;
  </select>
    <select id="selectOne"  resultType="Book" parameterType="int">
      //大概就是参数的类型
        select * from book where id=#{id};
    </select>
    <insert id="insert" keyProperty="id">
     insert into book(book.name,author,price) value(#{name},#{author},#{price})
    </insert>
    <insert id="insert1"   >
        insert into book(book.name,author,price) value(#{name},#{author},#{price})
    </insert>
    <update id="updateBy" parameterType="Book">
        update  book set name=#{name},
        <if test="author!=null and author !=''">
           author=#{author},</if>

        price = #{price} where id=#{id}


    </update>

    <delete id="deleteByid">
        delete from book where id=#{id}
    </delete>
<!--解决模糊查询
1 concat('%',#{author},'%') 拼接
在Java中调用的时候给定模糊查询限定符号
2 mapper.selectByAuthor("%金%");
给定固定的值
3'%${value}%'
4 '%' #{author} '%'
-->
    <select id="selectByAuthor" resultType="Book">
        select * from book where author like '%' #{author} '%'
    </select>


    <select id="OrderByPrice" resultType="Book">
        select  * from book order by ${value}
    </select>
</mapper>
posted @ 2022-07-26 14:13  java小寇  阅读(34)  评论(0)    收藏  举报