http://www.springcamp.io/2017/
ü ö
@RestController public class MyController { @GetMapping("/hello/{name}") String hello(@pathvariable String name) { return "Hello " + name; } }
@RestController public class MyController { @GetMapping("/hello/{name}") String hello(@pathvariable String name) { return "Hello " + name; } }
@RestController public class MyController { @GetMapping("/hello/{name}") String hello(@pathvariable String name) { return "Hello " + name; } }
@RestController public class MyController { @GetMapping("/hello/{name}") String hello(@pathvariable String name) { return "Hello " + name; } }
@RestController public class MyController { @GetMapping("/hello/{name}") String hello(@pathvariable String name) { return "Hello " + name; } }
@RestController public class MyController { @GetMapping("/hello/{name}") String hello(@pathvariable String name) { return "Hello " + name; } }
@FunctionalInterface public interface RouterFunction<T extends ServerResponse> { Mono<HandlerFunction<T>> route(serverrequest request);
@FunctionalInterface public interface RouterFunction<T extends ServerResponse> { Mono<HandlerFunction<T>> route(serverrequest request);
@FunctionalInterface public interface RouterFunction<T extends ServerResponse> { Mono<HandlerFunction<T>> route(serverrequest request);
@FunctionalInterface public interface RouterFunction<T extends ServerResponse> { Mono<HandlerFunction<T>> route(serverrequest request);
@FunctionalInterface public interface RouterFunction<T extends ServerResponse> { Mono<HandlerFunction<T>> route(serverrequest request);
@FunctionalInterface public interface RouterFunction<T extends ServerResponse> { Mono<HandlerFunction<T>> route(serverrequest request);
@FunctionalInterface public interface RouterFunction<T extends ServerResponse> { Mono<HandlerFunction<T>> route(serverrequest request);
@FunctionalInterface public interface HandlerFunction<T extends ServerResponse> { Mono<T> handle(serverrequest request); }
@FunctionalInterface public interface HandlerFunction<T extends ServerResponse> { Mono<T> handle(serverrequestrequest); }
@FunctionalInterface public interface HandlerFunction<T extends ServerResponse> { Mono<T> handle(serverrequestrequest); }
@FunctionalInterface public interface HandlerFunction<T extends ServerResponse> { Mono<T> handle(serverrequest request); }
@RestController public class MyController { @GetMapping("/hello/{name}") String hello(@pathvariable String name) { return "Hello " + name; } }
HandlerFunction hellohandler = req -> { String name = req.pathvariable("name"); Mono<String> result = Mono.just("Hello " + name); Mono<ServerResponse> res = ServerResponse.ok().body(result, String.class); return res; };
HandlerFunction hellohandler = req -> { String name = req.pathvariable("name"); Mono<String> result = Mono.just("Hello " + name); Mono<ServerResponse> res = ServerResponse.ok().body(result, String.class); return res; }; Mono<T> handle(serverrequestrequest);
HandlerFunction hellohandler = req -> { String name = req.pathvariable("name"); Mono<String> result = Mono.just("Hello " + name); Mono<ServerResponse> res = ServerResponse.ok().body(result, String.class); return res; };
HandlerFunction hellohandler = req -> { String name = req.pathvariable("name"); Mono<String> result = Mono.just("Hello " + name); Mono<ServerResponse> res = ServerResponse.ok().body(result, String.class); return res; };
HandlerFunction hellohandler = req -> { String name = req.pathvariable("name"); Mono<String> result = Mono.just("Hello " + name); Mono<ServerResponse> res = ServerResponse.ok().body(result, String.class); return res; };
HandlerFunction hellohandler = req -> { String name = req.pathvariable("name"); Mono<String> result = Mono.just("Hello " + name); Mono<ServerResponse> res = ServerResponse.ok().body(result, String.class); return res; };
HandlerFunction hellohandler = req -> ok().body(fromobject("hello " + req.pathvariable("name")));
HandlerFunction hellohandler = req -> ok().body(fromobject("hello " + req.pathvariable("name")));
HandlerFunction hellohandler = req -> ok().body(fromobject("hello " + req.pathvariable("name")));
HandlerFunction hellohandler = req -> ok().body(fromobject("hello " + req.pathvariable("name")));
HandlerFunction hellohandler = req -> ok().body(fromobject("hello " + req.pathvariable("name")));
@RestController public class MyController { @GetMapping("/hello/{name}") String hello(@pathvariable String name) { return "Hello " + name; } }
RouterFunction router = req -> RequestPredicates.path("/hello/{name}").test(req)? Mono.just(helloHandler) : Mono.empty();
RouterFunction router = req -> RequestPredicates.path("/hello/{name}").test(req)? Mono.just(helloHandler) : Mono.empty();
RouterFunction router = req -> RequestPredicates.path("/hello/{name}").test(req)? Mono.just(helloHandler) : Mono.empty();
RouterFunction router = req -> RequestPredicates.path("/hello/{name}").test(req)? Mono.just(helloHandler) : Mono.empty();
RouterFunction router = req -> RequestPredicates.path("/hello/{name}").test(req)? Mono.just(helloHandler) : Mono.empty(); Mono<HandlerFunction<T>> route(serverrequest request);
RouterFunction router = RouterFunctions.route(RequestPredicates.path("/hello/{name}"), req -> ServerResponse.ok().body(fromObject("Hello " + req.pathvariable("name"))));
RouterFunction router = RouterFunctions.route(RequestPredicates.path("/hello/{name}"), req -> ServerResponse.ok().body(fromObject("Hello " + req.pathvariable("name")))); RouterFunction router = req -> RequestPredicates.path("/hello/{name}").test(req)? Mono.just(helloHandler) : Mono.empty();
RouterFunction router = RouterFunctions.route(RequestPredicates.path("/hello/{name}"), req -> ServerResponse.ok().body(fromObject("Hello " + req.pathvariable("name")))); HandlerFunction hellohandler = req -> ok().body(fromobject("hello " + req.pathvariable("name")));
@Bean RouterFunction hellopathvarrouter() { return route(requestpredicates.path("/hello/{name}"), req -> ok().body(fromobject("hello " + req.pathvariable("name")))); }
HandlerFunction handler = req -> { String res = myservice.hello(req.pathvariable("name")); return ok().body(fromobject(res)); }; return route(path("/hello/{name}"), handler);
HandlerFunction handler = req -> { String res = myservice.hello(req.pathvariable("name")); return ok().body(fromobject(res)); }; return route(path("/hello/{name}"), handler);
@Component public class HelloHandler { @AutowiredMyService myservice; } Mono<ServerResponse> hello(serverrequest req) { String res = myservice.hello(req.pathvariable("name")); return ok().body(fromobject(res)); }
@Component public class HelloHandler { @AutowiredMyService myservice; Mono<ServerResponse> hello(serverrequest req) { String res = myservice.hello(req.pathvariable("name")); return ok().body(fromobject(res)); } }
@Bean RouterFunction hellorouter(@autowired HelloHandler hellohandler) { return route(path("/hello/{name}"), hellohandler::hello); }
@Bean RouterFunction hellorouter(@autowired HelloHandler hellohandler) { return route(path("/hello/{name}"), hellohandler::hello); }
@Bean RouterFunction hellorouter(@autowired HelloHandler hellohandler) { return route(path("/hello/{name}"), hellohandler::hello); }
public RouterFunction<?> routingfunction() { return nest(pathprefix("/person"), nest(accept(application_json), route(get("/{id}"), handler::getperson).androute(method(httpmethod.get), handler::listpeople) ).androute(post("/").and(contenttype(application_json)), handler::createperson)); }
public RouterFunction<?> routingfunction() { return nest(pathprefix("/person"), nest(accept(application_json), route(get("/{id}"), handler::getperson).androute(method(httpmethod.get), handler::listpeople) ).androute(post("/").and(contenttype(application_json)), handler::createperson)); }
public RouterFunction<?> routingfunction() { return nest(pathprefix("/person"), nest(accept(application_json), route(get("/{id}"), handler::getperson).androute(method(httpmethod.get), handler::listpeople) ).androute(post("/").and(contenttype(application_json)), handler::createperson)); }
public RouterFunction<?> routingfunction() { return nest(pathprefix("/person"), nest(accept(application_json), route(get("/{id}"), handler::getperson).androute(method(httpmethod.get), handler::listpeople) ).androute(post("/").and(contenttype(application_json)), handler::createperson)); }
public RouterFunction<?> routingfunction() { return nest(pathprefix("/person"), nest(accept(application_json), route(get("/{id}"), handler::getperson).androute(method(httpmethod.get), handler::listpeople) ).androute(post("/").and(contenttype(application_json)), handler::createperson)); }
public RouterFunction<?> routingfunction() { return nest(pathprefix("/person"), nest(accept(application_json), route(get("/{id}"), handler::getperson).androute(method(httpmethod.get), handler::listpeople) ).androute(post("/").and(contenttype(application_json)), handler::createperson)); }
@RestController public static class MyController { @RequestMapping("/hello/{name}") Mono<ServerResponse> hello(serverrequest req) { return ok().body(fromobject(req.pathvariable("name"))); }
@RestController public static class MyController { @RequestMapping("/hello/{name}") Mono<ServerResponse> hello(serverrequest req) { return ok().body(fromobject(req.pathvariable("name"))); }
@RestController public static class MyController { @RequestMapping("/hello/{name}") Mono<ServerResponse> hello(serverrequest req) { return ok().body(fromobject(req.pathvariable("name"))); }
@GetMapping("/hello/{name}") Mono<String> hello(@pathvariable String name) { return Mono.just("Hello " + name); }
@GetMapping("/hello/{name}") Mono<String> hello(@pathvariable String name) { return Mono.just("Hello " + name); }
@GetMapping("/hello/{name}") Mono<String> hello(@pathvariable String name) { return Mono.just("Hello " + name); }
@GetMapping("/hello/{name}") Mono<String> hello(@pathvariable String name) { return Mono.just("Hello " + name); }
@RequestMapping("/hello") Mono<String> hello(user user) { return Mono.just("Hello " + user.getname()); }
@RequestMapping("/hello") Mono<String> hello(user user) { return Mono.just("Hello " + user.getname()); }
@RequestMapping("/hello") Mono<String> hello(@requestbody User user) { return Mono.just("Hello " + user.getname()); }
@RequestMapping("/hello") Mono<String> hello(@requestbody User user) { return Mono.just("Hello " + user.getname()); }
@RequestMapping("/hello") Mono<String> hello(@requestbody Mono<User> user) { return user.map(u -> "Hello " + u.getname()); }
@RequestMapping("/hello") Mono<String> hello(@requestbody Mono<User> user) { return user.map(u -> "Hello " + u.getname()); }
@RequestMapping("/hello") Mono<String> hello(@requestbody Mono<User> user) { return user.map(u -> "Hello " + u.getname()); }
@PostMapping(value = "/hello") Flux<String> hello(@requestbody Flux<User> users) { return users.map(u -> "Hello " + u.getname()); }
@PostMapping(value = "/hello") Flux<String> hello(@requestbody Flux<User> users) { return users.map(u -> "Hello " + u.getname()); }
@PostMapping(value = "/hello") Flux<String> hello(@requestbody Flux<User> users) { return users.map(u -> "Hello " + u.getname()); }
@Async CompletableFuture<User> findonebyfirstname(string firstname);
@Async CompletableFuture<User> findonebyfirstname(string firstname);
@GetMapping Mono<User> finduser(string name) { return Mono.fromCompletionStage(myRepository.findOneByFirstName(name)); }
@GetMapping Mono<User> finduser(string name) { return Mono.fromCompletionStage(myRepository.findOneByFirstName(name)); }
@GetMapping Mono<User> finduser(string name) { return Mono.fromCompletionStage(myRepository.findOneByFirstName(name)); }
public interface ReactivePersonRepository extends ReactiveCrudRepository<Person, String> { Flux<Person> findbylastname(mono<string> lastname); @Query("{ 'firstname':?0, 'lastname':?1}") Mono<Person> findbyfirstnameandlastname(string firstname, String lastname); }
public interface ReactivePersonRepository extends ReactiveCrudRepository<Person, String> { Flux<Person> findbylastname(mono<string> lastname); @Query("{ 'firstname':?0, 'lastname':?1}") Mono<Person> findbyfirstnameandlastname(string firstname, String lastname); }
public interface ReactivePersonRepository extends ReactiveCrudRepository<Person, String> { Flux<Person> findbylastname(mono<string> lastname); @Query("{ 'firstname':?0, 'lastname':?1}") Mono<Person> findbyfirstnameandlastname(string firstname, String lastname); }
public interface ReactivePersonRepository extends ReactiveCrudRepository<Person, String> { Flux<Person> findbylastname(mono<string> lastname); @Query("{ 'firstname':?0, 'lastname':?1}") Mono<Person> findbyfirstnameandlastname(string firstname, String lastname); }
@AutowiredUserRepository userrepository; @GetMapping Flux<User> users() { return userrepository.findall(); }
@AutowiredUserRepository userrepository; @GetMapping Flux<User> users() { return userrepository.findall(); } Flux<T> findall();
@GetMapping Flux<String> users() { return userrepository.findall().map(u -> "Hello " + u.getname()); }
public Mono<ServerResponse> getperson(serverrequest request) { int personid = Integer.valueOf(request.pathVariable("id")); Mono<ServerResponse> notfound = ServerResponse.notFound().build(); Mono<Person> personmono = this.repository.getperson(personid); return personmono.flatmap(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject( person))).switchifempty(notfound); }
public Mono<ServerResponse> getperson(serverrequest request) { int personid = Integer.valueOf(request.pathVariable("id")); Mono<ServerResponse> notfound = ServerResponse.notFound().build(); Mono<Person> personmono = this.repository.getperson(personid); return personmono.flatmap(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject( person))).switchifempty(notfound); }
public Mono<ServerResponse> getperson(serverrequest request) { int personid = Integer.valueOf(request.pathVariable("id")); Mono<ServerResponse> notfound = ServerResponse.notFound().build(); Mono<Person> personmono = this.repository.getperson(personid); return personmono.flatmap(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject( person))).switchifempty(notfound); }
public Mono<ServerResponse> getperson(serverrequest request) { int personid = Integer.valueOf(request.pathVariable("id")); Mono<ServerResponse> notfound = ServerResponse.notFound().build(); Mono<Person> personmono = this.repository.getperson(personid); return personmono.flatmap(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject( person))).switchifempty(notfound); }
public Mono<ServerResponse> getperson(serverrequest request) { int personid = Integer.valueOf(request.pathVariable("id")); Mono<ServerResponse> notfound = ServerResponse.notFound().build(); Mono<Person> personmono = this.repository.getperson(personid); return personmono.flatmap(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject( person))).switchifempty(notfound); }
public Mono<ServerResponse> getperson(serverrequest request) { int personid = Integer.valueOf(request.pathVariable("id")); Mono<ServerResponse> notfound = ServerResponse.notFound().build(); Mono<Person> personmono = this.repository.getperson(personid); return personmono.flatmap(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject( person))).switchifempty(notfound); }
@GetMapping("/webclient") Mono<String> webclien() { return WebClient.create("http://localhost:8080").get().uri("/hello/{name}", "Spring").accept(MediaType.TEXT_PLAIN).exchange().flatMap(r -> r.bodytomono(string.class)).map(d -> d.touppercase()).flatmap(d -> hellorepository.save(d)); }
@GetMapping("/webclient") Mono<String> webclient() { WebClient wc = WebClient.create("http://localhost:8080"); UriSpec<RequestHeadersSpec<?>> urispec = wc.get(); RequestHeadersSpec<?> headerspec = urispec.uri("/hello/{name}", "Spring"); RequestHeadersSpec<?> headerspec2 = headerspec.accept(mediatype.text_plain); Mono<ClientResponse> res = headerspec2.exchange(); Mono<String> data = res.flatmap(r -> r.bodytomono(string.class)); Mono<String> upperdata = data.map(d -> d.touppercase()); return upperdata.flatmap(d -> hellorepository.save(d)); }
WebClient wc = WebClient.create("http://localhost:8080");
UriSpec<RequestHeadersSpec<?>> urispec = wc.get();
RequestHeadersSpec<?> headerspec = urispec.uri("/hello/{name}", "Spring");
RequestHeadersSpec<?> headerspec2 = headerspec.accept(mediatype.text_plain);
Mono<ClientResponse> res = headerspec2.exchange();
Mono<String> data = res.flatmap(r -> r.bodytomono(string.class));
Mono<String> upperdata = data.map(d -> d.touppercase());
return upperdata.flatmap(d -> hellorepository.save(d));
@GetMapping("/webclient") Mono<String> webclien() { return WebClient.create("http://localhost:8080").get().uri("/hello/{name}", "Spring").accept(MediaType.TEXT_PLAIN).exchange().flatMap(r -> r.bodytomono(string.class)).map(d -> d.touppercase()).flatmap(d -> hellorepository.save(d)); }