这里是我的示例代码:
String sql = yoursql;
Object args[] = new Object[3];
args[0] = yourparam1;
args[1] = yourparam2;
args[2] = yourparam3;
getJdbcTemplate().query(sql, args, yourRowMapper);
您应该为rowmapper添加以下代码。
private RowMapper yourRowMapper= new YourRowMapperClass();
public final class YourRowMapperClass implements RowMapper {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
YourResponse model = new YourResponse();
model.setresp1(rs.getDate(1));
model.setresp2(rs.getDate(2));
model.setresp3(rs.getString(3));
return model;
}
}
顺序对于指定参数很重要。例如,如果我们使用检索类别参数两次在我们的SQL,我们应该定义参数如下:
Object args[] = new Object[4];
args[0] = searchType;
args[1] = param1;
args[2] = searchType;
args[3] = param2;
如果我们为您定制的例子,你可以使用下面的代码:
Object args[] = new Object[10];
args[0] = appname;
args[1] = errorcode;
args[2] = appname;
args[3] = errorcode;
args[4] = appname;
args[5] = errorcode;
args[6] = appname;
args[7] = errorcode;
args[8] = appname;
args[9] = errorcode;
我改变了我代码并将其作为简单示例进行分享。如果你想要具体的例子,我可以尝试分享新的代码。 – ahmetdursun 2013-03-01 18:24:28
如何指定参数?我应该创建地图并将其作为参数传递吗?我需要在每个谓词中指定两个参数。 app_name&error_code。 – user1527483 2013-03-01 19:11:01
您不需要创建地图。订单对于指定很重要。我会编辑我的答案。 – ahmetdursun 2013-03-01 19:43:54