运用Lambda表达式来简化代码:
原代码:
sql = "select id,name,mobile,address from student where id =?"; /*class RowMapper implements IRowMapper { @Override public void rowMapper(ResultSet rs) { try { if(rs.next()) { String id = rs.getString("id"); String name = rs.getString("name"); String mobile = rs.getString("mobile"); String address = rs.getString("address"); System.out.println(id+","+name+","+mobile+","+address); } } catch (SQLException e) { e.printStackTrace(); } } }*/简化后:
/* IRowMapper rowMapper = (rs)-> { try { if(rs.next()) { String name = rs.getString("name"); String mobile = rs.getString("mobile"); String address = rs.getString("address"); System.out.println(id+","+name+","+mobile+","+address); } } catch (SQLException e) { e.printStackTrace(); } };