[spring boot] jdbc

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;
    }
}
    原文作者:locke
    原文地址: https://segmentfault.com/a/1190000018259813
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞