Springboot使用JdbcTemplate RowMapper查询,直接返回实体列表

出门莫恨无人随,书中车马多如簇。这篇文章主要讲述Springboot使用JdbcTemplate RowMapper查询,直接返回实体列表相关的知识,希望能为你提供帮助。
ManagerRowMapper.java

public class ManagerRowMapper implements RowMapper< Manager> {@Override public Manager mapRow(ResultSet rs, int i) throws SQLException { Manager m = new Manager(); m.setId(rs.getInt("ID")); m.setName(rs.getString("NAME")); m.setAge(rs.getInt("AGE")); m.setGender(rs.getString("GENDER")); m.setCreateDate(rs.getDate("CREATE_DATE")); m.setCreateBy(rs.getString("CREATE_BY")); return m; }}

使用
ManagerDao.java
public class ManagerDao { @Autowired private JdbcTemplate jdbcTemplate; public List< Manager> selectAll(){ String sql = "select * from TAB_MANAGER"; return jdbcTemplate.query(sql, new ManagerMapRow()); } }

【Springboot使用JdbcTemplate RowMapper查询,直接返回实体列表】 

    推荐阅读