【问题标题】:Spring.NET Equivalent for Java Spring Data Access UsageSpring.NET 等效于 Java Spring 数据访问用法
【发布时间】:2012-10-25 14:36:46
【问题描述】:

Spring.NET中的“SimpleJdbcCall”、“MapSqlParameterSource”和“BeanPropertySqlParameterSource”等价物是什么?如何在 Spring.NET 中编写下面的 Java:

publicvoid create(T object) {
if(object==null)
return null;
SimpleJdbcCall pspCreate = new SimpleJdbcCall(jdbcTemplate).withProcedureName("cr eate_sp").withReturnValue().declareParameters(new SqlOutParameter("id", Types.BIGINT));
SqlParameterSource in = new BeanPropertySqlParameterSource(object);
Map<String, Object> m = pspCreate.execute(in);
long id = m.containsKey(IDENTITY_VALUE)?(Long) m.get(IDENTITY_VALUE):0;
int resultCode =m.containsKey(RETURN_VALUE)?(Integer) m.get(RETURN_VALUE):0;
}


public List<T> retrieveAll(int pageNum, int pageSize) {
SqlParameterSource in = new MapSqlParameterSource()
.addValue("pageNum", pageNum, Types.INTEGER)
.addValue("pageSize", pageSize, Types.INTEGER);

SimpleJdbcCall pspRetrieveAll =new SimpleJdbcCall(jdbcTemplate).withProcedureName("re trieve_all_sp").withReturnValue().returningResultS et("LIST", BeanPropertyRowMapper.newInstance(UploadBatch.clas s)).returningResultSet(NO_OF_RECORDS, new RowMapper<Long>() {

@Override
public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getLong(1);
}
});
Map<String, Object> m = pspRetrieveAll.execute(in);
List<T> list=null;
if(m.containsKey(LIST))
list = (List<T>) m.get(LIST);

return list;
} 

【问题讨论】:

    标签: c# java spring spring.net data-access


    【解决方案1】:

    使用 ADO.NET 检查数据访问章节:

    http://www.springframework.net/doc-latest/reference/html/ado.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      • 2018-01-14
      相关资源
      最近更新 更多