public class MapSqlParameterSource extends AbstractSqlParameterSource
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.
addValue(String, Object)
,
addValue(String, Object, int)
,
AbstractSqlParameterSource.registerSqlType(java.lang.String, int)
,
NamedParameterJdbcTemplate
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.Object> |
values |
TYPE_UNKNOWN
Constructor and Description |
---|
MapSqlParameterSource()
Create an empty MapSqlParameterSource,
with values to be added via
addValue . |
MapSqlParameterSource(java.util.Map<java.lang.String,?> values)
Create a new MapSqlParameterSource based on a Map.
|
MapSqlParameterSource(java.lang.String paramName,
java.lang.Object value)
Create a new MapSqlParameterSource, with one value
comprised of the supplied arguments.
|
Modifier and Type | Method and Description |
---|---|
MapSqlParameterSource |
addValue(java.lang.String paramName,
java.lang.Object value)
Add a parameter to this parameter source.
|
MapSqlParameterSource |
addValue(java.lang.String paramName,
java.lang.Object value,
int sqlType)
Add a parameter to this parameter source.
|
MapSqlParameterSource |
addValue(java.lang.String paramName,
java.lang.Object value,
int sqlType,
java.lang.String typeName)
Add a parameter to this parameter source.
|
MapSqlParameterSource |
addValues(java.util.Map<java.lang.String,?> values)
Add a Map of parameters to this parameter source.
|
java.lang.String[] |
getParameterNames()
Enumerate all available parameter names if possible.
|
java.lang.Object |
getValue(java.lang.String paramName)
Return the parameter value for the requested named parameter.
|
java.util.Map<java.lang.String,java.lang.Object> |
getValues()
Expose the current parameter values as read-only Map.
|
boolean |
hasValue(java.lang.String paramName)
Determine whether there is a value for the specified named parameter.
|
getSqlType, getTypeName, registerSqlType, registerTypeName, toString
public MapSqlParameterSource()
addValue
.addValue(String, Object)
public MapSqlParameterSource(java.lang.String paramName, @Nullable java.lang.Object value)
paramName
- the name of the parametervalue
- the value of the parameteraddValue(String, Object)
public MapSqlParameterSource(@Nullable java.util.Map<java.lang.String,?> values)
values
- a Map holding existing parameter values (can be null
)public MapSqlParameterSource addValue(java.lang.String paramName, @Nullable java.lang.Object value)
paramName
- the name of the parametervalue
- the value of the parameterpublic MapSqlParameterSource addValue(java.lang.String paramName, @Nullable java.lang.Object value, int sqlType)
paramName
- the name of the parametervalue
- the value of the parametersqlType
- the SQL type of the parameterpublic MapSqlParameterSource addValue(java.lang.String paramName, @Nullable java.lang.Object value, int sqlType, java.lang.String typeName)
paramName
- the name of the parametervalue
- the value of the parametersqlType
- the SQL type of the parametertypeName
- the type name of the parameterpublic MapSqlParameterSource addValues(@Nullable java.util.Map<java.lang.String,?> values)
values
- a Map holding existing parameter values (can be null
)public java.util.Map<java.lang.String,java.lang.Object> getValues()
public boolean hasValue(java.lang.String paramName)
SqlParameterSource
paramName
- the name of the parameter@Nullable public java.lang.Object getValue(java.lang.String paramName)
SqlParameterSource
paramName
- the name of the parameter@NonNull public java.lang.String[] getParameterNames()
SqlParameterSource
This is an optional operation, primarily for use with
SimpleJdbcInsert
and SimpleJdbcCall
.
null
if not determinableSqlParameterSourceUtils.extractCaseInsensitiveParameterNames(org.springframework.jdbc.core.namedparam.SqlParameterSource)