数据库
首页 > 数据库> > 【springboot2】数据库连接操作

【springboot2】数据库连接操作

作者:互联网

导入依赖。

    <properties>
        <java.version>1.8</java.version>
        <mysql.version>5.1.49</mysql.version>
    </properties>
    
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <!--            <version>5.1.49</version>-->
    </dependency>

application.yaml

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mybatis_plus
    username: root
    password: rrddrrdd
    driver-class-name: com.mysql.jdbc.Driver

测试类

@Slf4j
@SpringBootTest
class Boot05WebAdminApplicationTests {

    @Autowired
    JdbcTemplate jdbcTemplate;


    @Test
    void contextLoads() {

//        jdbcTemplate.queryForObject("select * from account_tbl")
//        jdbcTemplate.queryForList("select * from account_tbl",)
        Long aLong = jdbcTemplate.queryForObject("select count(*) from account_tbl", Long.class);
        log.info("记录总数:{}",aLong);
    }

}

标签:account,数据库,class,springboot2,jdbcTemplate,mysql,连接,select,tbl
来源: https://blog.csdn.net/weixin_44600184/article/details/122635268