Skip to content

Instantly share code, notes, and snippets.

@nipunthathsara
Created June 20, 2022 21:37
Show Gist options
  • Save nipunthathsara/1ed6eb1a2e95477d128ccf0700e6091f to your computer and use it in GitHub Desktop.
Save nipunthathsara/1ed6eb1a2e95477d128ccf0700e6091f to your computer and use it in GitHub Desktop.
Medium SQLI - Fixed model class
@Component
public class SqliModel {
@Autowired
private JdbcTemplate jdbcTemplate;
public List<Page> getPage(String pageId) {
String sql = "SELECT pageId, title, content FROM pages WHERE pageId=?";
List<Page> pages = jdbcTemplate.query(
sql,
new Object[]{pageId},
(resultSet, rowNum) -> new Page(
resultSet.getInt("pageId"),
resultSet.getString("title"),
resultSet.getString("content"))
);
return pages;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment