SpringBoot整合JDBC、Mybatis、JPA

1、整合JDBC

①引入Jar包


		org.springframework.boot
		spring-boot-starter-jdbc
	
	
		mysql
		mysql-connector-java
		runtime
	

②配置application.yml

spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://47.104.95.243:3306/jdbc
    driver-class-name: com.mysql.jdbc.Driver

默认执行sql语句只需要在resources目录下新建文件
schema-.sql、data-.sql
默认规则:schema.sql,schema-all.sql;

可以使用下面的语言指定位置

schema:
   classpath:department.sql

2、整合Druid数据源(先引入jar包)
导入druid数据源

@Configuration
public class DruidConfig {
   

    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean
    public DataSource druid(){
   
       return  new DruidDataSource();
    }

    //配置Druid的监控
    //1、配置一个管理后台的Servlet
    @Bean
    public ServletRegistrationBean statViewServlet(){
   
        ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
        Map<String,String> initParams = new HashMap<>();

        initParams.put("loginUsername","admin");
        initParams.put("loginPassword","123456");
        initParams.put("allow","");//默认就是允许所有访问
        initParams.put("deny","192.168.15.21");

        bean.setInitParameters(initParams);
        return

你可能感兴趣的:(SpringBoot,数据库,JavaWEB,spring,spring,boot,mybatis)