Skip to content

Commit 01b2431

Browse files
author
Peter Vestlin
committed
Fixade jdbc.
1 parent e033be4 commit 01b2431

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies {
3939
compile "com.google.guava:guava:19.0"
4040

4141
compile "org.springframework.boot:spring-boot-devtools"
42+
compile 'org.liquibase:liquibase-core'
4243

4344

4445
testCompile 'junit:junit'

src/main/kotlin/nu/westlin/kartrepo/KartController.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ open class KartController @Autowired constructor(val kartRepository: KartReposit
1919
}
2020

2121

22-
@RequestMapping("/user")
22+
@RequestMapping("/driver")
2323
fun greeting(@RequestParam(value = "username", defaultValue = "pwestlin") username: String): Driver {
2424
return kartRepository.load(username)
2525
}
2626

27-
@RequestMapping("/users")
27+
@RequestMapping("/drivers")
2828
fun greeting(): List<Driver> {
29-
return listOf(Driver("pwestlin", "Peter", "Westlin"))
29+
return kartRepository.all()
3030
}
3131

3232
@ExceptionHandler(NotFoundException::class)

src/main/kotlin/nu/westlin/kartrepo/KartRepository.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ open class KartRepository @Autowired constructor(var jdbcOperations: JdbcOperati
2121
}
2222

2323
fun load(alias: String): Driver {
24-
return jdbcOperations.queryForObject("select alias,firstname,lastname from driver where alias=?", UserRowMapper(), alias)
24+
return jdbcOperations.queryForObject("select alias,firstname,lastname from driver where alias=?", DriverRowMapper(), alias)
2525
}
2626

27-
class UserRowMapper : RowMapper<Driver> {
27+
class DriverRowMapper : RowMapper<Driver> {
2828

2929
@Throws(SQLException::class)
3030
override fun mapRow(rs: ResultSet, rowNum: Int): Driver {
@@ -37,4 +37,8 @@ open class KartRepository @Autowired constructor(var jdbcOperations: JdbcOperati
3737

3838
}
3939

40+
fun all(): List<Driver> {
41+
return jdbcOperations.query<Driver>("select alias,firstname,lastname from driver", DriverRowMapper())
42+
}
43+
4044
}

0 commit comments

Comments
 (0)