public <T> Optional<T> queryForOptionalObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException {
        Optional<T> result;

        try {
            final T obj = super.queryForObject(sql, paramSource, rowMapper);
            result = Optional.ofNullable(obj);
        } catch (EmptyResultDataAccessException e) {
            result = Optional.empty();
        }

        return result;
    }
public < T > Optional < T > queryForOptionalObject ( String sql , SqlParameterSource paramSource , RowMapper < T > rowMapper ) throws DataAccessException { Optional < T > result ; try { final T obj = super . queryForObject ( sql , paramSource , rowMapper ) ; result = Optional . ofNullable ( obj ) ; } catch ( EmptyResultDataAccessException e ) { result = Optional . empty ( ) ; } return result ; }
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping a single result row to a
Java object via a RowMapper.
@param sql SQL query to execute
@param paramSource container of arguments to bind to the query
@param rowMapper object that will map one object per row
@param <T> The return object type
@return the single mapped object (optionally)
@throws org.springframework.dao.EmptyResultDataAccessException
if the query does not return exactly one row, or does not return exactly
one column in that row
@throws org.springframework.dao.DataAccessException if the query fails