33import org .springframework .http .HttpStatus ;
44import org .springframework .http .ResponseEntity ;
55import org .springframework .jdbc .core .JdbcTemplate ;
6+ import org .springframework .jdbc .core .RowMapper ;
67import org .springframework .jdbc .support .GeneratedKeyHolder ;
78import org .springframework .jdbc .support .KeyHolder ;
89import org .springframework .stereotype .Controller ;
10+ import org .springframework .web .bind .annotation .GetMapping ;
911import org .springframework .web .bind .annotation .PostMapping ;
1012import org .springframework .web .bind .annotation .RequestBody ;
13+ import org .springframework .web .bind .annotation .ResponseBody ;
1114import roomescape .model .time .Time ;
1215import roomescape .model .time .TimeRequest ;
1316
1417import java .sql .PreparedStatement ;
18+ import java .sql .ResultSet ;
19+ import java .sql .SQLException ;
20+ import java .util .List ;
1521
1622@ Controller
1723public class TimeController {
@@ -20,6 +26,21 @@ public class TimeController {
2026 public TimeController (JdbcTemplate jdbcTemplate ) {
2127 this .jdbcTemplate = jdbcTemplate ;
2228 }
29+ @ GetMapping ("/times" )
30+ @ ResponseBody
31+ public List <Time > getTimes () {
32+ String sql = "SELECT * FROM time" ;
33+ return jdbcTemplate .query (sql , new TimeRowMapper ());
34+ }
35+
36+ private static class TimeRowMapper implements RowMapper <Time > {
37+ @ Override
38+ public Time mapRow (ResultSet rs , int rowNum ) throws SQLException {
39+ Time time = new Time (rs .getString ("time" ));
40+ time .setId (rs .getLong ("id" ));
41+ return time ;
42+ }
43+ }
2344
2445 @ PostMapping ("/times" )
2546 public ResponseEntity <Time > createTimes (@ RequestBody TimeRequest timeRequest ) {
0 commit comments