这里做了比较清晰的解释: 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. bzoj 4439: [Swerc2015]Landscaping -- 最小割

    4439: [Swerc2015]Landscaping Time Limit: 2 Sec  Memory Limit: 512 MB Description FJ有一块N*M的矩形田地,有两种地形 ...

  2. Apache -- XAMPP Apache 无法启动原因及解决方法

    XAMPP Apache 无法启动原因1(缺少VC运行库): 这个就是我遇到的问题原因,下载安装的XAMPP版本是xampp-win32-1.7.7-VC9,而现有的Windows XP系统又没有安装 ...

  3. Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈

    B. Mike and Feet Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pro ...

  4. qt程序运行时的错误error:undefined reference to `_imp___ZN10QTcpSocketD1Ev'

    出现的错误: undefined reference to `_imp___ZN10QTcpSocketD1Ev' undefined reference to `_imp___ZN10QTcpSoc ...

  5. 【转】2012年6月26 – 盛大PHP工程师最新面试题

    无笔试. 口试:(前半部分平淡无奇,没什么太难的问题,都是求职岗位基本要会的东西,局限于php.下面是真正进入状态的题.) 谈谈观察者模式是什么?主要应用. 答:类似会有一些server对象时刻侦听某 ...

  6. nginx实现openfire负载均衡

    Nginx版本必须是1.9以上,不然不支持tcp连接,要么加入其他插件 在nginx.conf文件中加入下图中的代码,图中的ip与端口配成自己的,配置好后,客户端请求listen监听的端口,ip为ng ...

  7. springBoot 2.X-自定义拦截器

    package com.cx.springboot.myInter; import javax.servlet.http.HttpServletRequest; import javax.servle ...

  8. 树状数组求第K小值 (spoj227 Ordering the Soldiers &amp;&amp; hdu2852 KiKi&#39;s K-Number)

    题目:http://www.spoj.com/problems/ORDERS/ and pid=2852">http://acm.hdu.edu.cn/showproblem.php? ...

  9. Linux操作系统的种种集成开发环境

    Linux操作系统的种种集成开发环境 随着Linux的逐渐兴起,已经有为数众多的程序在上面驰骋了,许多开发环境(Development Environment)也应运而生.好的开发环境一定是集成了编辑 ...

  10. 关于禁用html中a标签的思考

    事实上这个问题在初次学习html中select标签时就已经冒出来了,时至今日,依旧没有找到使用纯css禁用a标签的办法--同事.同学.老师我都问过了,他们都千篇一律借助了JavaScript,难道真的 ...