国产成人毛片视频|星空传媒久草视频|欧美激情草久视频|久久久久女女|久操超碰在线播放|亚洲强奸一区二区|五月天丁香社区在线|色婷婷成人丁香网|午夜欧美6666|纯肉无码91视频

引入pom依賴

在使用Spring Boot進(jìn)行數(shù)據(jù)庫交互時,我們需要在項(xiàng)目的pom.xml文件中引入相關(guān)的依賴。具體依賴包括druid、mysql-connector-java和mybatis-spring-boo

在使用Spring Boot進(jìn)行數(shù)據(jù)庫交互時,我們需要在項(xiàng)目的pom.xml文件中引入相關(guān)的依賴。具體依賴包括druid、mysql-connector-java和mybatis-spring-boot-starter。

```xml

druid

1.0.20

mysql

mysql-connector-java

mybatis-spring-boot-starter

1.1.1

```

druid啟動配置

為了讓Spring Boot項(xiàng)目能夠使用druid連接池,我們需要在項(xiàng)目中添加一個配置類()。這個配置類主要完成三個任務(wù):設(shè)置連接參數(shù)、獲取SqlSessionFactory對象和獲取數(shù)據(jù)源。

```java

@Configuration

@MapperScan("mybatis") // 掃描mapper接口包

public class mybatisConfig implements EnvironmentAware {

@Resource

private Environment environment;

private RelaxedPropertyResolver propertyResolver;

// EnvironmentAware接口的默認(rèn)實(shí)現(xiàn)方法,默認(rèn)掃描屬性

public void setEnvironment(Environment environment) {

this.environment environment;

new RelaxedPropertyResolver(environment, "");

}

// 獲得SqlSessionFactory對象

@Bean

public SqlSessionFactory SqlSessionFactoryBean() throws Exception {

SqlSessionFactoryBean sqlSessionFactoryBean new SqlSessionFactoryBean();

(dataSource());

PathMatchingResourcePatternResolver resolver new PathMatchingResourcePatternResolver();

(("classpath*:mybatis/*.xml"));

return ();

}

// 獲得DataSource對象

@Bean

public DataSource dataSource() {

DruidDataSource druidDataSource new DruidDataSource();

(("driver-class-name"));

(("url"));

(("username"));

(("password"));

return druidDataSource;

}

}

```

增加啟動類和接口

標(biāo)簽: