天天看点

Spring Boot整合使用JdbcTemplate

1 pom文件引入

<!-- jdbcTemplate 依赖 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- mysql 依赖 -->
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
</dependency>
           

2 application.properties增加数据库配置

spring.datasource.url=jdbc:mysql://localhost:3306/xxxx
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
           

 3 service类使用JdbcTemplate

@Service
public class TestServiceImpl implements ITestService {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	 public void jdbcTemplate() {
        jdbcTemplate.queryForList("SELECT * FROM t_contents where 1 = 1 --");

    }
}
           

继续阅读