关于MyBatismapper的insert,update,delete返回值

您所在的位置:网站首页 xml返回list 关于MyBatismapper的insert,update,delete返回值

关于MyBatismapper的insert,update,delete返回值

2022-12-18 00:40| 来源: 网络整理| 查看: 265

返回值

这⾥做了⽐较清晰的解释

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 selectOne(String statement, Object parameter)

 List selectList(String statement, Object parameter)

 Map 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 selectOne(String statement)

 List selectList(String statement)

 Map selectMap(String statement, String mapKey)

int

 insert(String statement)

int

 update(String statement)

int

 delete(String statement)

⽽在

mapper

xml

不需要

(

也不能

)

insert, update, delete

指定

resultType, 

如这⾥所解释

insert, update, delete

只⽀持这些

Attributes: id, parameterType, parameterMap, flushCache, timeout, statementType, useGeneratedKeys,

keyProperty, keyColumn, databaseId



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3