spring 中的 RowMapper

刺骨的言语ヽ痛彻心扉 2022-08-05 15:03 231阅读 0赞

sping中的RowMapper可以将数据中的每一行数据封装成用户定义的类.

public final static String QUERY_SQL_NODE = “select n.id,n.name,n.ip, n.port ,n.type from t_Node n where n.type = “ + NodeType.CC.getChar();

public List getDCParameterListByQuery(ParameterQuery query) {
List list = null;

  1. RowMapper mapper = new RowMapper() \{
  2. public Object mapRow(ResultSet rs, int rowNum) throws SQLException \{
  3. ParameterModel info = new ParameterModel();
  4. info.setKey(rs.getString(1));
  5. info.setCode(rs.getString(2));
  6. info.setValue(rs.getString(3));
  7. info.setType(rs.getString(4));
  8. return info;
  9. \}
  10. \};
  11. try \{
  12. list = getJdbcTemplate().query(QUERY\_SQL\_PARAMETER\_KEY\_TYPE, new Object\[\] \{query.getKey() , query.getType()\} , mapper);
  13. \} catch (Exception ex) \{
  14. //ProcessorController.afterThrowing("iPGAccessDBError");
  15. log.error(ex);
  16. throw new AppRuntimeException(CommInfo.DATABASE\_EXCEPTION, ex.getCause());
  17. \}
  18. return list;
  19. \}

发表评论

表情:
评论列表 (有 0 条评论,231人围观)

还没有评论,来说两句吧...

相关阅读