MongDB怎么使用教程,整合到SpingBoot的WebFlux项目中去

1.引入三个核心依赖

    //spring-boot
    implementation 'org.springframework.boot:spring-boot-starter:2.6.3'
    //webflux
    implementation 'org.springframework.boot:spring-boot-starter-webflux:2.6.0'
    //mongoDb
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive:2.6.0'

2.编写代码 

实体类User:

package com.fdw.webflux.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.persistence.Id;

/**
 * @program: 
 * @description:
 * @author: 
 * @create: 2023-12-15 17:47
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "user")
public class User {
    @Id
    private String id;
    private String name;
    private int age;
}

dao层UserRepo

你可能感兴趣的:(Java开发实战知识经验分享,spring,java,mongodb)