@ConfigurationProperties(prefix = "spring.r2dbc")
public class R2dbcProperties {
/**
* Database name. Set if no name is specified in the url. Default to "testdb" when
* using an embedded database.
*/
private String name;
/**
* Whether to generate a random database name. Ignore any configured name when
* enabled.
*/
private boolean generateUniqueName;
/**
* R2DBC URL of the database. database name, username, password and pooling options
* specified in the url take precedence over individual options.
*/
private String url;
/**
* Login username of the database. Set if no username is specified in the url.
*/
private String username;
/**
* Login password of the database. Set if no password is specified in the url.
*/
private String password;
@Component
public class UsersService {
@Resource
private UsersDao usersDao;
@Transactional
public Mono<Users> save(Users user) {
return usersDao.save(user).map(it -> {
if (it.getFirstname().equals("flydean")) {
throw new IllegalStateException();
} else {
return it;
}
});
}
}
上面我们创建了一个save方法,用来保存相应的User对象。
controller
最后,我们创建一个controller来对外暴露相应的方法:
@RestController
@RequiredArgsConstructor
public class UsersController {
private final UsersDao usersDao;
@GetMapping("/users")
public Flux<Users> findAll() {
return usersDao.findAll();
}
}