zoukankan      html  css  js  c++  java
  • SpringBoot整合JdbcTemplate连接Mysql

    import java.io.IOException;
    
    import javax.sql.DataSource;
    
    import org.apache.ignite.IgniteSystemProperties;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.Bean;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.datasource.DriverManagerDataSource;
    
    
    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) throws IOException {
            
    
            SpringApplication.run(Application.class, args);
        }
    
        @Bean
        public JdbcTemplate jdbcTemplate() {
            DriverManagerDataSource dataSource = new DriverManagerDataSource();
            dataSource.setDriverClassName("com.mysql.jdbc.Driver");
            dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test");
            dataSource.setUsername("root");
            dataSource.setPassword("123456");
    
            JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
            return jdbcTemplate;
        }
    
    }

    添加依赖:

    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'

    springBoot {
    executable = true
    mainClass = 'com.test.Application'
    }

    dependencies {
    compile "org.springframework.boot:spring-boot-starter-web:${verSpringBoot}"

    compile "mysql:mysql-connector-java:5.1.21"

    }

  • 相关阅读:
    Mybatis核心
    正则表达式(二)Java中正则表达式的使用
    Elasticsearch(ES)分词器的那些事儿
    并发编程之:JUC并发控制工具
    scrollTo()和scrollBy()的区别
    SpringBoot 的@Value注解太强大了,用了都说爽!
    SQL 查询并不是从 SELECT 开始的
    jsoup 教程
    爬虫
    case when以及集合聚合函数的用法
  • 原文地址:https://www.cnblogs.com/liangblog/p/10387769.html
Copyright © 2011-2022 走看看