Created
May 18, 2018 12:52
-
-
Save soudmaijer/5a67d928a74d22d2beed25da8ab996ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.jdbc.core.JdbcTemplate | |
import org.springframework.jdbc.core.RowMapper | |
import org.springframework.stereotype.Repository | |
@Repository | |
class OrderRepository(private val jdbcTemplate: JdbcTemplate) { | |
private val rowMapper: RowMapper<Order> = RowMapper { rs, i -> Order(rs.getLong("id")) } | |
fun findOrderById(id: Long): Order? { | |
val result = jdbcTemplate.query<Order>("select * from orders where id=:id", rowMapper, id) | |
if (result.size > 1) throw RuntimeException("Too many results from findOrderById.") | |
return result.firstOrNull() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment