Lambda表达式

    技术2023-03-27  98

    运用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(); } };

     

    Processed: 0.018, SQL: 9