美文网首页
MyBatis的dao层mapper配置

MyBatis的dao层mapper配置

作者: 又双叒叕苟了一天 | 来源:发表于2018-01-30 19:04 被阅读0次

    mapper.xml

    <mapper namespace="所对应的接口">
      <sql id="sql1">sql语句起别名</sql>
    
      <select id="和接口中方法对应" parameterType="int" resultType="user">
      <include refid="sql1">或select语句
      </select>
    
      <select id="模糊查询" parameterType="String" parameterType="user">
      select * from user where username like '%${value}%'
     </select>
    
      //插入并返回主键
      <insert id="方法名" parameterType="user">
        <selectKey keyProperty="id" order="AFTER" resultType="int">
        select last_insert_id();
        </selectKey>
        insert into user(..) values(#{username}..)  
      </insert>
    
      update/delete同理
    </mapper>
    

    其余标签:

    <where>
      <if test="username!=null and sex!=''">
      and username like '%${username}%'
      </if>
      <if>..
    </where>
    
    <foreach collection="ids//list变量名" item="id" open="id in (" close=")" separator=",">
    #{id}
    </foreach>
    

    注意:占位符#{}和连接符${}区别
    占位符自带''
    连接符不带''用于like

    相关文章

      网友评论

          本文标题:MyBatis的dao层mapper配置

          本文链接:https://www.haomeiwen.com/subject/pqeczxtx.html