Created
October 28, 2017 18:10
-
-
Save dnaismyth/a0fde0e86291196adc9731f1f224e741 to your computer and use it in GitHub Desktop.
Adding our RowMapper and SQL query
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 java.sql.ResultSet; | |
import java.sql.SQLException; | |
import org.springframework.jdbc.core.RowMapper; | |
import org.springframework.stereotype.Repository; | |
import tutorial.springsetup.entity.Game; | |
@Repository | |
public class GameJDBCRepository extends BaseJDBCRepository { | |
private final String SQL_SEARCH_BY_DESCRIPTION = "SELECT description, id, title FROM game g WHERE lower(g.description) LIKE lower(:desc);"; | |
private class GameRowMapper implements RowMapper<Game> { | |
public Game mapRow(ResultSet rs, int rowNum) throws SQLException { | |
Game game = new Game(); | |
game.setDescription(rs.getString("description")); | |
game.setId(rs.getLong("id")); | |
game.setTitle(rs.getString("title")); | |
return game; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment