Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Summary of MyBatis placeholders and splices

Shulou Source: shulou.com Published: 2022-06-03 04:41:34 11月25日 Update

-- placeholders and splices

# {} represents a placeholder. Through # {}, you can set values from preparedStatement to placeholders and convert java types and jdbc types automatically. # {} can effectively prevent sql injection. # {} can receive simple type values or pojo attribute values. If parameterType transmits a single simple type value, the # {} parentheses can be value or other names.

${} means concatenating sql strings. Through ${}, the content passed in by parameterType can be spliced into sql without jdbc type conversion. ${} can receive simple type values or pojo attribute values. If parameterType transmits a single simple type value, it can only be value in ${} parentheses.

Z

A

ParameterType and resultType

ParameterType: specifies the input parameter type, and mybatis gets the parameter values from the input object through ognl to concatenate them in sql.

ResultType: specifies the type of output result, and mybatis maps a row of record data from the sql query result to an object of the type specified by resultType. If there are multiple pieces of data, map them separately and put the objects in the container List.

Z

A

SelectOne and selectList

SelectOne queries a record. If you use selectOne to query multiple records, an exception is thrown:

Org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne (), but found: 3

At org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne (DefaultSqlSession.java:70)

SelectList can query one or more records.

Tags: Type query multiple object single parameter attribute parenthesis data result transfer input valid line content name container symbol setting output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux Redmi vpn macOS