Skip to content

Instantly share code, notes, and snippets.

@yanhua365
Created February 17, 2014 09:00
Show Gist options
  • Save yanhua365/9047130 to your computer and use it in GitHub Desktop.
Save yanhua365/9047130 to your computer and use it in GitHub Desktop.
Hibernate里使用Spring JdbcTemplate的代码。来自appfuse的UserDaoHibernate。
public String getUserPassword(Long userId) {
JdbcTemplate jdbcTemplate =
new JdbcTemplate(SessionFactoryUtils.getDataSource(getSessionFactory()));
Table table = AnnotationUtils.findAnnotation(User.class, Table.class);
return jdbcTemplate.queryForObject(
"select password from " + table.name() + " where id=?", String.class, userId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment