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
TYPE_UNKNOWN
Constructor and Description |
---|
MapSqlParameterSource()
Create an empty MapSqlParameterSource,
with values to be added via
addValue . |
MapSqlParameterSource(Map<String,?> values)
Create a new MapSqlParameterSource based on a Map.
|
MapSqlParameterSource(String paramName,
Object value)
Create a new MapSqlParameterSource, with one value
comprised of the supplied arguments.
|
Modifier and Type | Method and Description |
---|---|
MapSqlParameterSource |
addValue(String paramName,
Object value)
Add a parameter to this parameter source.
|
MapSqlParameterSource |
addValue(String paramName,
Object value,
int sqlType)
Add a parameter to this parameter source.
|
MapSqlParameterSource |
addValue(String paramName,
Object value,
int sqlType,
String typeName)
Add a parameter to this parameter source.
|
MapSqlParameterSource |
addValues(Map<String,?> values)
Add a Map of parameters to this parameter source.
|
String[] |
getParameterNames()
Enumerate all available parameter names if possible.
|
Object |
getValue(String paramName)
Return the parameter value for the requested named parameter.
|
Map<String,Object> |
getValues()
Expose the current parameter values as read-only Map.
|
boolean |
hasValue(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(String paramName, @Nullable Object value)
paramName
- the name of the parametervalue
- the value of the parameteraddValue(String, Object)
public MapSqlParameterSource addValue(String paramName, @Nullable Object value)
paramName
- the name of the parametervalue
- the value of the parameterpublic MapSqlParameterSource addValue(String paramName, @Nullable Object value, int sqlType)
paramName
- the name of the parametervalue
- the value of the parametersqlType
- the SQL type of the parameterpublic MapSqlParameterSource addValue(String paramName, @Nullable Object value, int sqlType, 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 Map<String,?> values)
values
- a Map holding existing parameter values (can be null
)public Map<String,Object> getValues()
public boolean hasValue(String paramName)
SqlParameterSource
paramName
- the name of the parameter@Nullable public Object getValue(String paramName)
SqlParameterSource
paramName
- the name of the parameter@NonNull public 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)