【springboot2】数据库连接 *** 作

【springboot2】数据库连接 *** 作,第1张

【springboot2】数据库连接 *** 作

导入依赖

    
        1.8
        5.1.49
    
    
    
        mysql
        mysql-connector-java
        
    

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);
    }

}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5709605.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-18
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存