springboot 整合 webflux 入门(restful)

Springboot 整合 webflux

1.pom.xml 写入 webflux 与 mongodb-reactive的坐标

	
   		 org.springframework.boot
   		 spring-boot-starter-data-mongodb-reactive
	
	
    	org.springframework.boot
    	spring-boot-starter-webflux
	

2.Application.properties 写入 monogdb的配置

spring.data.mongodb.host=localhost
spring.data.mongodb.database=jjj
spring.data.mongodb.port=27017
spring.data.mongodb.username=iii
spring.data.mongodb.password=xxx

3.Model

@Document
@Date
	public class Apple implements Serializable {
   	 	@Id
    	private String id;
    	private String name;
}

4.持久层继承 ReactiveMongoRepository

@Repository
public interface AppleRepository extends ReactiveMongoRepository {
}

5.本教程舍去了逻辑业务层,直接在控制层使用

@RestController
@RequestMapping("apple")
public class AppleController {
    @Autowired
    AppleRepository appleRepository;

    @PostMapping
    public Mono  save(@RequestBody Apple  apple){
        Mono save = appleRepository.save(apple);
        return save;
    };

    @GetMapping
    public Mono  getById(@RequestParam String  id){
        Mono byId = appleRepository.findById(id);
        return byId;
    };
}

6.启动

你可能感兴趣的:(springboot,框架)