Category Archives: Java

Spring Boot – Create REST API Basic (Hello World)

Hey guys 👋In the last tutorial we have been already learn about create new spring boot application. In this tutorial, we will learn how to create REST API basic in spring boot. Spring Boot – Create REST API Basic (Hello World) First, create new package or folder with name “controller”. Second, create new java class with name “HelloController.java”. After that… Read More »

WebFlux Pagination For Reactive Spring Data

In this example I’m trying to create wrapper for pagination with reactive code in spring 5. I have created simple rest endpoint for finding all entities using spring web-flux and spring data reactive mongoDB with pagination. WebFlux Pagination For Reactive Spring Data In Spring Data 1.0, we have PagingAndSortingRepository which inherits from CrudRepository. In reactive Spring Data, we… Read More »

What Is Spring Boot?

Spring Boot is a framework created by Pivotal. Spring Boot is very popular in java community because this framework can make it easy to create stand-alone web application. This framework is designed to simplify the bootstrapping and development of a new Spring application. Developers just need a very little Spring configuration to run web application, because the framework takes an… Read More »

Spring Data MongoDB – Upsert

In this tutorial i will share to you how to use UpSert operation in spring data mongoDB. If no document that matches the query, a new document is created by combining the query and update object. @Autowired private MongoTemplate mongoTemplate; //search a document that doesn’t exist Query query = new Query(); query.addCriteria(Criteria.where(“id”).is(“cimblo”)); Update update = new Update(); update.set(“age”,… Read More »

Spring Data MongoDB – Save Or Update

In this tutorial you will learn how to save or update data into database using spring data mongoDB. Spring Data MongoDB – Save Or Update First declare “Mongo Template”, then do save or update : @Autowired private MongoTemplate mongoTemplate; Mongo Template Save User user = new User(); user.setName(“cimblo”); user.setAge(99); //save data with save() function mongoTemplate.save(userTest1); Mongo Template Update… Read More »

Spring RestTemplate With Cookie In Header

Spring rest template hit endpoint with cookie in header can be like this: RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.ALL)); headers.add(“Cookie”, “ID=SPRING-JAVA”); HttpEntity entity = new HttpEntity<>(headers); ResponseEntity response = restTemplate.exchange( “https://www.cimblo.com”, HttpMethod.GET, entity, String.class); Spring RestTemplate With Cookie In Header In this example i’m using java 8 and spring boot version 1.5.8 with… Read More »

Open URL On Web Browser With JAVA (Linux, Mac, Windows)

If you need to open link on browser with java code, you can do with this code. Runtime rt = Runtime.getRuntime(); String url = “https://www.cimblo.com“; try { rt.exec(“open ” + url); } catch (IOException e) { e.printStackTrace(); } Open URL On Web Browser With JAVA (Linux, Mac, Windows) That code currently will work on Linux, Mac, Ubuntu and… Read More »

Spring Data MongoDB LIKE Query Insensitive Case ‘%%’

With spring data mongoDB you can do “LIKE QUERY” like example below. Query query = new Query(); query.addCriteria(Criteria.where(“name”).regex(“yourString”, “i”)); mongoTemplate.find(query, CodingExample.class) Spring Data MongoDB LIKE Query Insensitive Case Spring Data MongoDB The Spring Data MongoDB project provides integration with the MongoDB document database. Key functional areas of Spring Data MongoDB are a POJO centric model for interacting with… Read More »