31.2 JdbcTemplate 사용
Spring의 클래스 JdbcTemplate와 NamedParameterJdbcTemplate클래스는 @Autowire로 자동으로 구성되며 다음 예제와 같이 직접 bean에 넣을 수 있습니다.
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;
}
// ...
}다음 예제와 같이 spring.jdbc.template.*속성 을 사용하여 템플릿의 일부 속성을 사용자 정의 할 수 있습니다 .
spring.jdbc.template.max-rows = 500![[노트]](https://wannaqueen.gitbook.io/spring5/~gitbook/image?url=https%3A%2F%2Fdocs.spring.io%2Fspring-boot%2Fdocs%2Fcurrent%2Freference%2Fhtmlsingle%2Fimages%2Fnote.png&width=300&dpr=4&quality=100&sign=e1be9d3c&sv=2)
NamedParameterJdbcTemplate 뒤에서 동일한 JdbcTemplate인스턴스를 재사용합니다. 둘 이상의 JdbcTemplate이 정의되고 기본 후보가없는 경우 NamedParameterJdbcTemplate은 자동으로 구성되지 않습니다.
Last updated
Was this helpful?