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 --");

    }
}

猜你喜欢

转载自blog.csdn.net/zhaolinxuan1/article/details/82908548