/**
 * @author wf.zhang
 */
@RestController
public class HelloController {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @GetMapping("/query")
    public Map<String, Object> map() {
        List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from user ");
        return list.get(0);
    }
}

application.yml

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/jdbc?useSSL=true&serverTimezone=UTC&characterEncoding=UTF8
    data-username: root
    data-password: root
    #initialization-mode: always
    #schema=classpath: schema.sql
    #schema=classpath: user.sql
    #data=classpath: data.sql

run  启动类

结果  查询第一个

SpringBoot2.2.2 使用 JdbcTemplate

 

 数据库

SpringBoot2.2.2 使用 JdbcTemplate

 

 

查询所有

/**
 * @author wf.zhang
 */
@RestController
public class HelloController {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @GetMapping("/query")
    public  List<Map<String, Object>> list() {
        List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from user ");
        return list;
    }
}

结果

SpringBoot2.2.2 使用 JdbcTemplate

 

 数据库创建表和数据 请看 https://www.cnblogs.com/wf-zhang/p/12163577.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-10-28
猜你喜欢
  • 2021-12-30
  • 2022-01-06
  • 2021-09-20
  • 2021-10-10
  • 2021-06-01
  • 2021-09-29
相关资源
相似解决方案