Skip to content

Instantly share code, notes, and snippets.

@krnbr
Last active July 23, 2020 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krnbr/ca25aa02ca7c642f05b6991c863cdbd9 to your computer and use it in GitHub Desktop.
Save krnbr/ca25aa02ca7c642f05b6991c863cdbd9 to your computer and use it in GitHub Desktop.
TestController And TestDto
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import javax.validation.Valid;
/**
* @author Karanbir Singh on 07/23/2020
*/
@RestController
public class TestController {
@GetMapping("test")
public Mono<TestDto> getTestDto(final @RequestParam String name,
final ServerWebExchange exchange) {
TestDto testDto = new TestDto();
testDto.setName(name);
testDto.setAge(0);
testDto.setName("Welcome "+name);
return Mono.just(testDto);
}
@PostMapping("test")
public Mono<TestDto> postTestDto(@Valid @RequestBody final TestDto testDto,
final ServerWebExchange exchange) {
return Mono.just(testDto);
}
}
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* @author Karanbir Singh on 07/23/2020
*/
public class TestDto {
@NotEmpty
private String message;
@NotEmpty
private String name;
@NotNull
private Integer age;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment