mybatis

一、mybatis各部分之间的关系(在此只分析mapper动态代理的),

  mybatis,主要是SqlMapConfig.xml、mapper.xml(user.xml)、dao接口、测试

  1.首先在SqlMapConfig.xml里面需要注入user. xml ,该累放在src下可以正常运行,放在src的子包里时测试时可能会报错。  

     <mappers>     <mapper resource="config/sqlMap/User.xml"/>      </mappers>

  2.mapper.xml中namespace要注入要实现的Dao接口的地址    <mapper namespace="com.itheima.mybatis.Dao.userMapper">

    <select>标签里的id必须与Dao接口里面的方法名一样,在此 parameterType 是输入的值,resultType是返回的值

    <select id="selectById" parameterType="int" resultType="com.itheima.mybatis.pojo.User">

      SELECT * FROM `user` WHERE id = #{id}
     </select>

  3.Dao如果用mapper的动态代理,不需要写实现类,如果用dao实现,需要写实现类。

  4测试类,在测试时需要加载SqlMapConfig.xml

posted @ 2019-03-06 23:28  清风吹不散  阅读(99)  评论(0编辑  收藏  举报