RowMapper可以将数据中的每一行封装成用户定义的类,在数据库查询中,如果返回的类型是用户自定义的类型则需要包装.
eg: 以下例子即可说明,可以在mapRow方法中实现数据封装,并返回自己所需要的类型。
List users = (List) getJdbcTemplate().query("SELECT * FROM " + SchemaUtil.getCMSSchema() + Constants.S_USER, smartUserMapper);
private RowMapper smartUserMapper = new RowMapper() {public Object mapRow(ResultSet rs, int rowNum) throws SQLException {User user = new User();user.setSUserId(rs.getInt(Constants.SMART_USER_ID));user.setCreated(rs.getDate("CREATED"));user.setDescription(rs.getString("DESCRIPTION"));user.setEmailAddr(rs.getString("EMAIL_ADDR"));user.setImsi(rs.getString("IMSI"));user.setIpAddr(rs.getString("IP_ADDR"));user.setIsactive(rs.getString("ISACTIVE"));user.setName(rs.getString("NAME"));user.setPassword(rs.getString("PASSWORD"));user.setTelephoneNum(rs.getString("TELEPHONE_NUM"));user.setWvpdn(rs.getString("WVPDN"));user.setCommunityCode(rs.getString("COMMUNITY_CODE"));return user;}};