我以简单的方式使用SimpleJdbcTemplate和MapSqlParameterSource:
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
parameterSource.addValue("typeId", typeId, Types.BIGINT);
List ids = _jdbcTemplate.query(_selectIdByParameters, new EntityIdRowMapper(), parameterSource);
当typeId(这是一个Long)为空时,查询的查询方式如下:
SELECT id FROM XXX WHERE typeId = null
而我期望它产生
SELECT id FROM XXX WHERE typeId IS NULL
You will have to provide the appropriate SQL statement based on your query parameters.
因此我的代码散布着空白的检查.
是否有更优雅的方式处理发送给SimpleJdbcTemplate的空参数?