首页 > 其他 > 详细

MyBatis框架学习笔记(1)

时间:2016-10-19 02:11:30      阅读:164      评论:0      收藏:0      [点我收藏+]

1. Mybatis向dao层传入能够连接交互数据库并进行操作的对象  
sqlSession 作用:
- 向sql语句传入参数
- 执行sql语句
- 获取执行sql语句后的结果
- 事务的控制

2.  如何得到SqlSession:
- 通过配置文件获取数据库连接相关信息
- 通过配置的相关信息构建SqlSessionFactory
- 通过SqlsessionFactory打开 数据库会话(SqlSession)

3.  实体映射文件配置Mapper
数据库中的数据类型跟jdbc中的Type中的常量有着对应关系
    <resultMap>
        <id />//映射为主键字段
        <result />//映射为普通字段
    </resultMap>//用于映射实体


     <resultMap type="com.huangdong.bean.Student" id="UserResult">
            <id column="Sno" jdbcType="INTEGER" property="Sno"/>
            <result column="Sname" jdbcType="VARCHAR" property="Sname"/>
            <result column="Ssex" jdbcType="VARCHAR" property="Ssex"/>
            <result column="Sdept" jdbcType="VARCHAR" property="Sdept"/>
     </resultMap>

    <select id="getStudentList" parameterType="long" resultMap="StudentResult">
       SELECT * FROM Student WHERE id = #{id:INTEGER}
    </select>
- property:实体属性
- column:表字段名称
- resultMap属性指向resultMap标签相应的id

MyBatis框架学习笔记(1)

原文:http://www.cnblogs.com/ZengHuangDong/p/5975427.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!