Skip to content

Instantly share code, notes, and snippets.

//This method is accepting documentId as argument and checks whether the document exists
boolean isExists = couchbaseTemplate.exists("E3");
public List<Employee> getEmployeeUsingCustomQuery(String name) {
//creating query on the basis of empName
String statement = "select empName, empId, META().id AS _ID, META().cas AS _CAS from Bucket1 where empName=$empName";
JsonObject placeHolder = JsonObject.create().put("empName", name);
N1qlQuery n1qlQuery = N1qlQuery.parameterized(statement, placeHolder);
//findbyN1QL method query the N!QL service and mapped to the Employee class.
return couchbaseTemplate.findByN1QL(n1qlQuery, Employee.class);
}
public Mono<UserDetails> callToExternalService() {
return WebClient
.builder()
.baseUrl("https://jsonplaceholder.typicode.com")
.build()
.get()
.uri("posts/1")
.exchange()
.flatMap(clientResponse -> clientResponse.bodyToMono(UserDetails.class));
public Mono<UserDetails> callToExternalService() {
return client
.get()
.uri("posts/1")
.retrieve()
.bodyToMono(UserDetails.class);
}
WebClient client = WebClient.builder()
.baseUrl("https://jsonplaceholder.typicode.com")
.build();
//create() Method accepts the String value as parameter. Here, we are initializing with the baseUrl.
WebClient webClient = WebClient.create("https://jsonplaceholder.typicode.com")
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
public class Person {
String id;
@FutureAndWithinSevenDays
String dateValue;
String name;
}
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
public class FutureAndWithinSevenDaysValidator implements ConstraintValidator<FutureAndWithinSevenDays, String> {
@Override
public final boolean isValid(final String value,
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)