关于MyBatis mapper的insert, update, delete返回值
2015-08-24 18:12
483 查看
这里做了比较清晰的解释: 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.
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.
而在mapper的xml中, 不需要(也不能)给insert, update, delete指定resultType, 如这里所解释
http://mybatis.github.io/mybatis-3/sqlmap-xml.html
insert, update, delete只支持这些Attributes: id, parameterType, parameterMap, flushCache, timeout, statementType, useGeneratedKeys, keyProperty, keyColumn, databaseId
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
insert, update, delete只支持这些Attributes: id, parameterType, parameterMap, flushCache, timeout, statementType, useGeneratedKeys, keyProperty, keyColumn, databaseId
相关文章推荐
- Android中View绘制优化之一---- 优化布局层次
- Android 的 Handler 总结
- 登录和注册,记住密码小例子,希望可以帮助大家
- 论文笔记 《Deep Neural Networks for Object Detection》
- Android 中 PopupWindow 响应返回键并关闭的问题
- android的SDK的新兼容包
- unity3d 各功能的运行秩序,打回来,订购,的次数
- Android Drawable 那些不为人知的高效用法
- Android 加载长图
- Android WebView常见问题解决方案
- Android MediaScanner 详尽分析
- iOS中关联对象的简单使用(objc_setAssociatedObject)
- Android初学习 - 在Service里面启动Activity
- cocos2d-x 计算两点之间的夹角
- iOS 深入理解“属性”及其关键字
- Android中通过typeface设置字体
- unity, 集成iOS广告sdk注意事项
- Android 自定义控件 轻松实现360软件详情页
- Android Studio NDK 开发配置
- 开源 android 文件管理器