Posts

Showing posts from 2021

Custom Exception Handling For Spring Boot Rest Controller

Image
There can be a scenario where we want to send a custom success or error message as a response to the Rest API call. This can be easily achievable using @ControllerAdvice annotation by implementing Custom Exception Handler. It can be either global error message or controller level messages. Here I am going to explain how to implement a global exception handler in spring boot. Below are the steps to implement custom error response in Spring boot Rest Controller   Implement a custom exception handler by extending ResponseEntityExceptionHandler with @ControllerAdvice annotation. Implement a Custom Exception.  Design a CustomApiException Response Model. Throw custom exception from Rest Service. Step 1 - Implementing a Custom Exception Handler When implementing a custom exception handler either you can implement a custom method to handle the exception or override the default "handleException" method  Example to implement a custom exception handler method...

Get rid of boring for loop and try using "range" and "rangeClosed"

Most of the Java developer already started using Java 15 but here is the feature in java 8  which  i want  to introduce to the people who doesn't  know about it or may be not using it. Lets see about two static methods  "range()" and "rangeClosed()". Usage  These two methods are available in IntStream and LongStream. IntStream -  IntStream class is an specialization of Stream interface for int primitive. It represents an stream of primitive int-valued elements supporting sequential and parallel aggregate operations.  IntStream is part of the java. util. stream package and implements AutoCloseable and BaseStream interfaces. Syntax range It returns the sequential ordered IntStream .It includes only the startInclusive value . static  IntStream  range( int  startInclusive ,  int  endInclusive) rangeClosed It returns the sequential ordered IntStream .It includes startInclusive and endInclusive values . static IntStream rangeCl...

Create MultiSelect Dropdown using vue-multiselect

If you are working with bootstrap vue you might be noticed that bootstrap-vue doesn't have a searchable multi-select drop down yet. There are a lot of other vue plugins that provide this feature. I found vue-multiselect as a better one. It supports searchable multi-select dropdown with Vuex. It also has multiple props that can be used to parse option data. Let us create a simple vue-multi-select dropdown . Step 1: Install vue/multiselect via npm           npm install vue-multiselect --save Step 2: Import multiselect component inside vue file where ever its is used              <template>              </template>              <script>               import Multiselect from "vue-multiselect";              export default {         ...