【第六章】SpringBoot整合

【第六章】SpringBoot整合MongoDB

第六章:springboot整合mongoDB

标签(空格分隔): mongoDB

依赖包(org.springframework.boot:spring-boot-starter-data-mongodb)

buildscript {
    ext {
        springBootVersion = '1.5.8.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-mongodb')
    runtime('org.springframework.boot:spring-boot-devtools')
    compile('org.springframework.boot:spring-boot-starter-test')
}

配置文件(springboot自动配置)

增删改查

定义数据库对象

定义接口,MongoRepository里已近有crud操作,这里可以定义额外的接口

测试类

启动类

Last updated

Was this helpful?