@EnableR2dbcRepositories
@Configuration
public class R2dbcConfig {
@Bean
public R2dbcEntityTemplate r2dbcEntityTemplate(DatabaseClient databaseClient) {
return new R2dbcEntityTemplate(databaseClient);
}
}
操作数据库
@Repository
public interface UserInfoDao extends ReactiveCrudRepository<UserInfo, Long> {
@Query("SELECT * FROM t_user_info WHERE id = :id and name = :name limit 1")
Mono<UserInfo> findDateByIdAndName(Long id, String name);
}
使用
@RestController
public class UserInfoController {
@Autowired
UserInfoDao userInfoDao;
@GetMapping("/getUserInfo")
public Mono<UserInfo> getUserInfo() {
return userInfoDao.findById(1L);
}
}