返回一個(gè)對(duì)象
官網(wǎng)示例:<T> T selectOne(String statement)
結(jié)果:
可能為 null汪榔。
注:
使用返回一個(gè)對(duì)象時(shí)柔纵,若數(shù)據(jù)庫(kù)查詢結(jié)果超過(guò)一條 record阐枣,Mybatis 則拋出非檢查類(lèi)異常TooManyResultsException
eg. :org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
證明查詢出兩條
返回一個(gè) List
官網(wǎng)示例:<E> List<E> selectList(String statement)
結(jié)果:
如果沒(méi)有返回值佑钾,那么就是一個(gè)空的 list悠鞍,不會(huì)出現(xiàn) null 的情況弓坞,所以使用時(shí)不用進(jìn)行判空,直接循環(huán)處理即可拉宗。
官網(wǎng)對(duì)接口定義的解釋?zhuān)?/h4>
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)
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)