欢迎访问『www.cnblogs.com/blog-ice』

1.增加依赖
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

2.初始化sql(resources/init.sql)
spring.sql.init.schema-locations=classpath:init.sql

3.注入JdbcTemplate
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/")
    public String index() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from users");
        return maps.toString();
    }

4.启用/h2-console控制台页面
spring.h2.console.enabled=true


 

posted on 2022-02-16 09:09  仙路尽头谁为峰  阅读(145)  评论(0编辑  收藏  举报
这里是自由发挥的天堂