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. I2C总线的仲裁机制

    在多主的通信系统中.总线上有多个节点,它们都有自己的寻址地址,可以作为从节点被别的节点访问,同时它们都可以作为主节点向其他的节点发送控制字节和传 送数据.但是如果有两个或两个以上的节点都向总线上发送启 ...

  2. Static变量与代码块

    * static:是一个关键字,用于修饰成员变量和成员方法 * static的特点: * 被所有的对象所共享 * 可以使用类名调用 * 静态的加载优先于对象 * 随着类的加载而加载 * static的 ...

  3. poj 1159 Palindrome - 动态规划

    A palindrome is a symmetrical string, that is, a string read identically from left to right as well ...

  4. 【python002-设计小游戏】

    用python设计第一个游戏 一.运行idle的快捷方式:F5 二.首先设计一款小游戏: print('-------开启python学习之旅--------')temp = input(" ...

  5. Python3基础 dict fromkeys 多个键对应相同的值

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. 什么是TF-A?

    1. TF-A的全称是什么? Arm Trusted Firmware 2. TF-A的作用是什么? 在secure world和non-secure world之间切换 3. TF-A涉及到哪几个部 ...

  7. (转)Awsome Domain-Adaptation

    Awsome Domain-Adaptation 2018-08-06 19:27:54 This blog is copied from: https://github.com/zhaoxin94/ ...

  8. (转载)c# winform comboBox的常用一些属性和用法

    comboBox的常用一些属性和用法 [1].控件的默认值怎么设? this.comboBox1.Text = "请选择港口"; comboBox1.Items.Add(" ...

  9. Writing device drivers in Linux: A brief tutorial

    “Do you pine for the nice days of Minix-1.1, when men were men and wrote their own device drivers?”  ...

  10. 洛谷P1803 凌乱的yyy dp

    我要日更嘤嘤嘤>_< 原题戳>>https://www.luogu.org/problem/show?pid=1803<<(其实是戳不动的,复制粘贴吧) 题目背景 ...