mybatis中session.getMapper()方法和resultMap


session.getMapper()方法的使用:

定义接口

  /**
* 查询所有
* @return
*/
public List<Student> getAll();

 

SQL映射文件,做如下设置

 

<mapper namespace="cn.happy.dao.IStudentDAO">

 

 

<select id="getAll" resultMap="studentMap" useCache="false">
select * from student
</select>

</mapper>

测试类:
/**
* 查询所有
*/
@Test
public void getAll() throws Exception{
SqlSession session = MyBatisUtil.getSession();
IStudentDAO mapper = session.getMapper(IStudentDAO.class);
List<Student> all = mapper.getAll();
for (Student item:all){
System.out.println(item.getId()+ item.getName()+ item.getAge());
}
//提交事务
session.commit();
//关闭会话,释放资源
session.close();
}

resultMap实现结果映射

 

 

 

 
 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM