这里做了比较清晰的解释: 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. mybatis源码分析(1)-----sqlSessionFactory创建

    1. 首先了解一下mybatis,包含核心jar ,以及spring相关jar. <!-- Mybatis相关组件 --> <dependency> <groupId&g ...

  2. WebDriver工作原理

    http://www.cnblogs.com/timsheng/archive/2012/06/12/2546957.html 通过研究selenium-webdriver的源码,笔者发现其实webd ...

  3. uboot启动内核的实现

    前面我们分析了uboot 的整个流程,我们知道uboot启动以后所有功能都是通过命令来实现的,启动kernel就是执行了bootcmd里面的命令.命令执行过程在uboot中是非常重要的现在我们就来看u ...

  4. 如何注入值到Spring bean属性

    在Spring中,有三种方式注入值到 bean 属性. 正常的方式 快捷方式 “p” 模式 看到一个简单的Java类,它包含两个属性 - name 和 type.稍后将使用Spring注入值到这个 b ...

  5. SQL Server 2008内存及I/O性能监控

    来源: it168  发布时间: 2011-04-12 11:04  阅读: 10820 次  推荐: 1   原文链接   [收藏]   以下均是针对Window 32位系统环境下,64位的不在下面 ...

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

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

  7. Gulp插件autoprefixer的使用

    1.创建:gulpfile.js //引入插件 var gulp = require('gulp'); var autoprefixer = require('gulp-autoprefixer'); ...

  8. 介紹 IIS 8 全新的 HttpPlatformHandler 模組與 ASP.NET 5 Beta8 重大變更

    HttpPlatformHandler 是一個支援 IIS 8 與 IIS 8.5 的原生模組 (native module),主要使用於 Microsoft Azure Websites 網站服務中 ...

  9. Java:泛型在编译时会被檫除,Eclipse 如何给出智能提示?

    背景 Java 的泛型是一种语法糖,编译时会被“檫除”,参考文章:http://docs.oracle.com/javase/tutorial/java/generics/,如果没有源代码,Eclip ...

  10. combogrid获取多个字段的方法

    var g = $('#cc').combogrid('grid'); // 获取表格控件对象var r = g.datagrid('getSelected'); //获取表格当前选中行alert(r ...