spring jdbc直接返回为对象

//返回单个对象
( User)jdbcTemplate.queryForObject("select * from USER where userId='"+userId+"'", new BeanPropertyRowMapper(User.class));

返回list

		List<User> list =(List<User>) jdbcTemplate.query(sql,new RowMapper (){
			@Override
			public User  mapRow(ResultSet rs, int index) throws SQLException {
				User user  = new User();
				....
				return user;
			}
		});



你可能感兴趣的:(spring jdbc直接返回为对象)