MyBatis tutorial

MyBatis is a Java persistence framework. It is easy to use and learn. This tutorial shows the most common scenarios.

MyBatis first level cache example

The first level cache is enabled by default in MyBatis. It will cache the result after querying data from database. The second time you query MyBatis won't hit db. The first level cache is for session. If the session is close the cache will be cleared. I assume that you have created database and insert some data in your table.

PostgreSQL desc table

In MySQL you can use desc to show the details of table. There is no desc command in PostgreSQL, but you can use \d or \d+ to show the table detail.

Spring Boot Swagger2 example

Swagger can help you generate document for your restful API. This blog will show you how to use it. I assume that you have known how to use Spring Boot. The structure of example project is like following.

Java Compare JSON string example

Use jsonassert framework to compare two json are same or not. It only compare the content of them. The example code is here;

PostgreSQL list all tables

Use \d or \d+ in psql command to show all tables. \d+ will show additional detail of tables;

Spring ResponseBody without null field

The annotation @ResponseBody can help you convert object to json. Sometimes if the field of object is null the json returned like following.

Linux list and set environment variable

Use set command to list all environment variables. They are like following in my computer.

Linux show folder(directory) size

Use du command to show the size of folder. Before testing this command we will create a directory and a file.

PostgreSQL switch database

In PosgreSQL there are several ways to switch database.

PostgreSQL show databases

In PostgreSQL there are two ways to list all databases.

Unable to open debugger port in Intellij IDEA

When I start tomcat to deploy my application I got the error message like following.

Java POI read excel example

It's easy to use Apache POI read excel file. Let's say you have an excel file. The path of it is D:\test.xlsx. The content is like following.

Java8 stream collect list to map in order

We can convert list to map easily in Java8 by using stream. The sample code is like following.

Java Executors newFixedThreadPool example

Executors.newFixedThreadPool(3) method will create a thread pool with only 3 threads. When we put Runnable or Callable object into the thread pool. The thread pool will create new thread for running task. When the number of threads equals the pool size the new task will be queued. The code below may help you have a better understanding of the the method newFixedThreadPool().