Class MapSqlParameterSource
java.lang.Object
org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource
org.springframework.jdbc.core.namedparam.MapSqlParameterSource
- All Implemented Interfaces:
SqlParameterSource
SqlParameterSource
implementation that holds a given Map of parameters.
This class is intended for passing in a simple Map of parameter values
to the methods of the NamedParameterJdbcTemplate
class.
The addValue
methods on this class will make adding several values
easier. The methods return a reference to the MapSqlParameterSource
itself, so you can chain several method calls together within a single statement.
- Since:
- 2.0
- Author:
- Thomas Risberg, Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.jdbc.core.namedparam.SqlParameterSource
TYPE_UNKNOWN
-
Constructor Summary
ConstructorDescriptionCreate an empty MapSqlParameterSource, with values to be added viaaddValue
.MapSqlParameterSource
(String paramName, Object value) Create a new MapSqlParameterSource, with one value comprised of the supplied arguments.MapSqlParameterSource
(Map<String, ?> values) Create a new MapSqlParameterSource based on a Map. -
Method Summary
Modifier and TypeMethodDescriptionAdd a parameter to this parameter source.Add a parameter to this parameter source.Add a parameter to this parameter source.Add a Map of parameters to this parameter source.String[]
Enumerate all available parameter names if possible.Return the parameter value for the requested named parameter.Expose the current parameter values as read-only Map.boolean
Determine whether there is a value for the specified named parameter.Methods inherited from class org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource
getSqlType, getTypeName, registerSqlType, registerTypeName, toString
-
Constructor Details
-
MapSqlParameterSource
public MapSqlParameterSource()Create an empty MapSqlParameterSource, with values to be added viaaddValue
.- See Also:
-
MapSqlParameterSource
Create a new MapSqlParameterSource, with one value comprised of the supplied arguments.- Parameters:
paramName
- the name of the parametervalue
- the value of the parameter- See Also:
-
MapSqlParameterSource
Create a new MapSqlParameterSource based on a Map.- Parameters:
values
- a Map holding existing parameter values (can benull
)
-
-
Method Details
-
addValue
Add a parameter to this parameter source.- Parameters:
paramName
- the name of the parametervalue
- the value of the parameter- Returns:
- a reference to this parameter source, so it's possible to chain several calls together
-
addValue
Add a parameter to this parameter source.- Parameters:
paramName
- the name of the parametervalue
- the value of the parametersqlType
- the SQL type of the parameter- Returns:
- a reference to this parameter source, so it's possible to chain several calls together
-
addValue
public MapSqlParameterSource addValue(String paramName, @Nullable Object value, int sqlType, String typeName) Add a parameter to this parameter source.- Parameters:
paramName
- the name of the parametervalue
- the value of the parametersqlType
- the SQL type of the parametertypeName
- the type name of the parameter- Returns:
- a reference to this parameter source, so it's possible to chain several calls together
-
addValues
Add a Map of parameters to this parameter source.- Parameters:
values
- a Map holding existing parameter values (can benull
)- Returns:
- a reference to this parameter source, so it's possible to chain several calls together
-
getValues
Expose the current parameter values as read-only Map. -
hasValue
Description copied from interface:SqlParameterSource
Determine whether there is a value for the specified named parameter.- Parameters:
paramName
- the name of the parameter- Returns:
- whether there is a value defined
-
getValue
Description copied from interface:SqlParameterSource
Return the parameter value for the requested named parameter.- Parameters:
paramName
- the name of the parameter- Returns:
- the value of the specified parameter
-
getParameterNames
Description copied from interface:SqlParameterSource
Enumerate all available parameter names if possible.This is an optional operation, primarily for use with
SimpleJdbcInsert
andSimpleJdbcCall
.- Returns:
- the array of parameter names, or
null
if not determinable - See Also:
-