mybatis
解决列名和属性名不一致:
1.为列名起别名,别名和属性名一致
<!--根据id查询学生信息-->
<select id="findOne" resultType="com.dsf.entity.Student">
select stu_id id,stu_name name,stu_age age from tb_stu where stu_id=#{id}
</select>
2.使用resultMap进行映射
<resultMap id="StuMapper" type="com.dsf.entity.Student">
<!--主键的映射关系 column:列名 property:属性名-->
<id column="stu_id" property="id"/>
<!--普通列的映射关系-->
<result column="stu_name" property="name"/>
<result column="stu_age" property="age"/>
</resultMap>
mybatis的关联查询:
<association>:多对一
<collection>:一对多
mybatis的缓存机制:
一级缓存:SqlSession级别的缓存,缓存的数据只在SqlSession内有效
二级缓存:mapper(SqlSessionFactory)级别的缓存,同一个namespace公用这一个缓存,所有对SqlSession是共享的

浙公网安备 33010602011771号