码迷,mamicode.com
首页 > 数据库 > 详细

MyBatis-session-SqlSession

时间:2018-05-23 23:39:06      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:.com   poj   self   insert   state   ret   ppi   rollback   lis   

The SqlSession instance is the most powerful in MyBatis.

It is where you‘ll find all of the methods to execute statements, commit or rollback transactions and acquire mapper instances.

There are over 20 methods on the SqlSession class.

  • 1. Statement Execution

These methdos are used to execute SELECT, INSERT, UPDATE and DELETE statemnets that are defined in your SQL Mapping XML files, There are pretty self expanatory, each takes the ID(defined in <select> in XXXMapper.xml) of the statement and the Parameter Object,which can be a primitive (auto-boxed or wrapper), a JavaBean, a POJO or a Map.

技术分享图片

  • 2. selectOne和selectList的区别:

selectOne必须返回exactly one object or null(none).

如果超过一个,就会抛出异常.

如果不知道多少个对象,使用selectList.

如果你像检查一个对象的存在, 最好返回一个count(0 or 1).

selectMap 是一个特殊的情况.他是被设计用来convert a list of results into a Map based on one of the properties in the resulting objects.(不懂) .

因为不是所有的语句都需要参数,这些方法也被重载为不需要参数对象的版本.

技术分享图片

最后,还有三个高级版本的select方法.它们允许你限制返回行数的范围, or provide custom result handing logic, 通常用于大的数据集合.

技术分享图片

 

MyBatis-session-SqlSession

标签:.com   poj   self   insert   state   ret   ppi   rollback   lis   

原文地址:https://www.cnblogs.com/zienzir/p/9080181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!