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的更多相关文章

  1. java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSession

    在配置一个springmvc+mybatis的项目时,总是有报一个错误: org.springframework.beans.factory.BeanCreationException: Error ...

  2. 【报错】java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession

    报错 java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession 或者 java.lang.ClassNotFound ...

  3. 简单探讨spring整合mybatis时sqlSession不需要释放关闭的问题

    https://blog.csdn.net/RicardoDing/article/details/79899686 近期,在使用spring和mybatis框架编写代码时,sqlSession不需要 ...

  4. MyBatis获取SqlSession

    package com.ykmimi.dao; import org.apache.ibatis.session.SqlSession; import com.ykmimi.entity.Studen ...

  5. SSM-MyBatis-10:Mybatis中SqlSession的getMapper()和简单的工具类MyBatisUtils

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- getMapper的作用,获取到接口,直接通过点的方式调用方法,以免直接手打的方式写错方法名,(强类型的方式) ...

  6. MyBatis 入门到精通(一) 了解MyBatis获取SqlSession

    MyBatis是什么? MyBatis是一款一流的支持自定义SQL.存储过程和高级映射的持久化框架.MyBatis几乎消除了所有的JDBC代码,也基本不需要手工去设置参数和获取检索结果.MyBatis ...

  7. SSM-MyBatis-07:Mybatis中SqlSession的insert和delete底层到底做了什么

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 先点进去看一下insert方法 用ctrl加鼠标左键点进去看 发现是一个接口SqlSession的方法,没有实 ...

  8. spring中的mybatis的sqlSession是如何做到线程隔离的?

    项目中常常使用mybatis配合spring进行数据库操作,但是我们知道,数据的操作是要求做到线程安全的,而且按照原来的jdbc的使用方式,每次操作完成之后都要将连接关闭,但是实际使用中我们并没有这么 ...

  9. Mybatis的SqlSession运行原理

    前言 SqlSession是Mybatis最重要的构建之一,可以简单的认为Mybatis一系列的配置目的是生成类似 JDBC生成的Connection对象的SqlSession对象,这样才能与数据库开 ...

  10. 使用ThreadLocal管理Mybatis中SqlSession对象

    转自http://blog.csdn.net/qq_29227939/article/details/52029065 public class MybatisUtil { private stati ...

随机推荐

  1. 零基础Python爬虫实现(爬取最新电影排行)

    提示:本学习来自Ehco前辈的文章, 经过实现得出的笔记. 目标网站 http://dianying.2345.com/top/ 网站结构 要爬的部分,在ul标签下(包括li标签), 大致来说迭代li ...

  2. 【TensorFlow】tf.nn.max_pool实现池化操作

    max pooling是CNN当中的最大值池化操作,其实用法和卷积很类似 有些地方可以从卷积去参考[TensorFlow]tf.nn.conv2d是怎样实现卷积的? tf.nn.max_pool(va ...

  3. Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

  4. Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin.

    原因:使用负载均衡的时候,第一次请求phpMyAdmin主页的时候web01进行处理,页面返回的cookie存放在web01上.填写用户名密码提交之后,是web02进行处理的,此时给页面的cookie ...

  5. 【做题】zoj3649 Social Net——倍增

    这题是吴老师推荐的,于是我就去做了. 根据题意,在完成最大生成树后,对于树上从x到y的一条路径,求出最大的ck-cj(j<=k,ci为路径上第i个点的权值). 我一开始的想法是二分,记路径xy的 ...

  6. P3301 [SDOI2013]方程

    思路 容斥的挺好的练习题 对于第二个条件,可以直接使m减去suma2,使得第二个条件舍去,然后m再减去n,使得问题转化成有n1个变量要满足小于等于某个数的条件,其他的随便取,求整数解的个数 对n1,以 ...

  7. (zhuan) Attention in Neural Networks and How to Use It

    Adam Kosiorek About Attention in Neural Networks and How to Use It this blog comes from: http://akos ...

  8. Deep Learning framework --- MexNet 安装,测试,以及相关问题总结

    Deep Learning framework --- MexNet 安装,测试,以及相关问题总结  一.安装:   参考博文:http://www.open-open.com/lib/view/op ...

  9. Thread类的常用方法

    String getName() 返回该线程的名称. void setName(String name) 改变线程名称,使之与参数 name 相同. int getPriority() 返回线程的优先 ...

  10. 最大匹配字符串LCS,The Longest Common Substring

    public enum BackTracking { UP, LEFT, NEITHER, UP_AND_LEFT } public abstract class LCSBaseMatch { /// ...