Spring的JdbcTemplate和NamedParameterJdbcTemplate类会被自动配置,你可以将它们直接@Autowire到自己的beans:
JdbcTemplate
NamedParameterJdbcTemplate
@Autowire
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; @Component public class MyBean { private final JdbcTemplate jdbcTemplate; @Autowired public MyBean(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } // ... }
Last updated 5 years ago