这里做了比较清晰的解释: http://mybatis.github.io/mybatis-3/java-api.html

SqlSession

As mentioned above, the SqlSession instance is the most powerful class 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 twenty methods on the SqlSession class, so let's break them up into more digestible groupings.

Statement Execution Methods
These methods are used to execute SELECT, INSERT, UPDATE and DELETE statements that are defined in your SQL Mapping XML files. They are pretty self explanatory, each takes the ID of the statement and the Parameter Object, which can be a primitive (auto-boxed or wrapper), a JavaBean, a POJO or a Map.

<T> T selectOne(String statement, Object parameter)
<E> List<E> selectList(String statement, Object parameter)
<K,V> Map<K,V> selectMap(String statement, Object parameter, String mapKey)
int insert(String statement, Object parameter)
int update(String statement, Object parameter)
int delete(String statement, Object parameter)

The difference between selectOne and selectList is only in that selectOne must return exactly one object or null (none). If any more than one, an exception will be thrown. If you don't' know how many objects are expected, use selectList. If you want to check for the existence of an object, you're better off returning a count (0 or 1). The selectMap is a special case in that it is designed to convert a list of results into a Map based on one of the properties in the resulting objects. Because not all statements require a parameter, these methods are overloaded with versions that do not require the parameter object.

The value returned by the insert, update and delete methods indicate the number of rows affected by the statement.

<T> T selectOne(String statement)
<E> List<E> selectList(String statement)
<K,V> Map<K,V> selectMap(String statement, String mapKey)
int insert(String statement)
int update(String statement)
int delete(String statement)

而在mapper的xml中, 不需要(也不能)给insert, update, delete指定resultType, 如这里所解释

http://mybatis.github.io/mybatis-3/sqlmap-xml.html

http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html

insert, update, delete只支持这些Attributes: id, parameterType, parameterMap, flushCache, timeout, statementType, useGeneratedKeys, keyProperty, keyColumn, databaseId

insert可以通过下面的方式指定返回值。。。

<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="id">
select LAST_INSERT_ID();
</selectKey>

update和delete的返回值是实际数据库中受到影响的记录的数目。参看 https://stackoverflow.com/questions/34653120/what-are-the-return-values-for-the-mybatis-update-functions

mybatis select/insert/update/delete的更多相关文章

  1. 数据操纵:SELECT, INSERT, UPDATE, DELETE

    SELECT 句法 SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [SQL_CACHE ...

  2. C++使用Mysql的详细步骤及各个常用方法的代码演示:select,insert,update,delete

    这几天一直在学习C++下使用Mysql的方法及其中各种的问题,也看了很多Mysql的API函数,当然自己看的还是很基础的.其实对于每种数据库的操作,基本的方法都是非常类似的,大多都是connect,s ...

  3. 数据库--MyBatis的(insert,update,delete)三种批量操作

    转自:http://blog.csdn.net/starywx/article/details/23268465 前段时间由于项目赶期没顾上开发过程中的性能问题,现对部分代码进行优化的过程中发现在数据 ...

  4. SQL基础语法的单表操作 select|insert|update|delete(增删改查) 简单使用

    以下案列以此表举例 1.select(查询) select简单的查询分为两种 注:字段也就是表结构中的列的名称 第一种: select  字段名  from  表名 此种查询只列出你所需要查询的字段, ...

  5. SQL基础语法select|insert|update|delete(增删改查) 简单使用

    以下案列以此表举例 1.select(查询) select简单的查询分为两种 注:字段也就是表结构中的列的名称 第一种: select  字段名  from  表名 此种查询只列出你所需要查询的字段, ...

  6. springboot @Select @Insert @Update @Delete

    https://blog.csdn.net/qq_20867981/article/details/80641353 使用@Select.@Insert.@Update.@Delete注解代替xxxM ...

  7. oracle中execute immediate的使用(select/insert/update/delete)(转)

    execute immediate的语法如下: execute immediate 'sql'; execute immediate 'sql_select' into var_1, var_2; e ...

  8. 关于MyBatis mapper的insert, update, delete返回值

    这里做了比较清晰的解释: http://mybatis.github.io/mybatis-3/java-api.html SqlSession As mentioned above, the Sql ...

  9. mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干

    1.mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干 2.一般来说,事务是必须满足4个条件(ACID): Atomicity(原子性).Con ...

随机推荐

  1. 中国剩余定理 hdu 1573 X问题

    HDU 1573 X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. Ural 1519 Formula 1 插头DP

    这是一道经典的插头DP单回路模板题. 用最小表示法来记录连通性,由于二进制的速度,考虑使用8进制. 1.当同时存在左.上插头的时候,需要判断两插头所在连通块是否相同,若相同,只能在最后一个非障碍点相连 ...

  3. python开发_python代码风格(coding style)

    我们要做python开发,我想python中的代码风格我们有必要了解一下 这样对我们自己和他们所编写的代码都有好处的. 下面是8点重要代码风格注意事项: ONE : Use 4-space inden ...

  4. 修改Linux默认启动级别或模式

    在Linux中有7种启动级别,默认是X-Window,像是Windows的窗口模式,而Linux的操作和配置一般我们都采用输入命令的方式来完成,像DOS操作系统一样,如何让Linux一启动就进入这种模 ...

  5. [置顶] think in java interview-高级开发人员面试宝典(三)

    收集自Oracle公司的10次(60道)电话面试全部问答(英语) Q: What environment variables do I need to set on my machine in ord ...

  6. Linux的进程优先级NI和PR

    为什么要有进程优先级? 这似乎不用过多的解释,毕竟自从多任务操作系统诞生以来,进程执行占用cpu的能力就是一个必须要可以人为控制的事情.因为有的进程相对重要,而有的进程则没那么重要. 进程优先级起作用 ...

  7. Appium+python自动化18-brew、carthage和appium-doctor

    前言 本篇安装brew.carthage,解决启动appium时的报错问题,另外安装appium-doctor检查appium的环境 1.brew 2.carthage 3.appium-doctor ...

  8. [android] Activity 的生命周期 以及横屏竖屏切换时 Activity 的状态变化

    生命周期Android 系统在Activity 生命周期中加入一些钩子,我们可以在这些系统预留的钩子中做一些事情.例举了 7 个常用的钩子:protected void onCreate(Bundle ...

  9. [Windows]_[删除非空文件夹的注意要点]

    场景: 1. 有时候程序须要生成一些暂时文件夹和暂时文件,在程序退出时须要删除,这时候用win32的api就可以完毕需求.自己遍历文件夹一个个removefile并非高效率的做法. //注意: //1 ...

  10. windows环境按照dcm4chee

    背景: dcm4chee是dcm4che开源项目中的一部分,是一款符合IHE规定的影像管理/归档应用.dcm4chee遵循DICOM.HL7标准,实现了图像存储.图像提取.及健康领域的工作流程管理.d ...