[spring boot] jdbc

78次阅读

共计 732 个字符,预计需要花费 2 分钟才能阅读完成。

1、pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
2、application.properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://10.24.73.247:5002/waimai?characterEncoding=utf8
spring.datasource.username=
spring.datasource.password=
3、JdbcTemplate
@RestController
public class DBController {

@Autowired
private JdbcTemplate jdbcTemplate;

@GetMapping(“/query”)
public Object load() {
String sql = “select * from wm_act_poi_v2 where wm_poi_id = 515”;
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
return result;
}
}

正文完
 0