Catch exception in MyBatis

I generate mapper interface and xml file in my application. There is no exception in method signature. But when the sql execute failed MyBatis will throw an exception. I found the exception thrown from MyBatis is always PersistenceException. After reading the source code, I seemed to understand.

Add border in table CSS example

In this page I will show you how to add border CSS in table. It is better add border in table before adjusting width and height. Example is here

Difference between text() html() and val() in JQuery

Do not know which to use when you want set or change the content of selector in JQuery? I will show you the difference between text(), html() and val() in this page. Example is here, copy it and save as html file. Click different button will change different selector's content.

Javascript switch case example is useful and easy to use in Javascript. I will show you how to use in Javascript. Examples are here.

JQuery loop array example

In this page I will show you how to loop an array by using JQuery and Javascript. I recommend using JQuery to loop an array. Examples are here.

Change character set in MySQL

Recently I met Chinese garbled(中文乱码) problem in MySQL. Solve this problem by changing the character. In this page I will show you how to change character in MySQL. Before changing it we need to know the support character sets in MySQL.

Update null or not exist field in MongoDB

Use db.collection.update to update the document. Do not know how to update document you can click Update document in MongoDB. In this page I will show you how to update document which field is null or not exists.

Count document in MongoDB

Use db.collection.count() to count the number of documents. You can add a query filter to count the specific documents. Examples are here.

Remove the last character in Java

StringUtils in apache-common-lang3 framework is an useful class. You can use removeEnd to remove the last character or characters. If you want remove the character and ignore the case use removeEndIngoreCase instead.

Update document in MongoDB

We use db.collection.update() to update the document. Since version 3.2 you can use db.collection.updateOne() ,db.collection.updateMany() or db.collection.replaceOne() to update document or documents. Click here for more detail. In this page I will show you simple examples.

Encoding(garbled) problem in SpringMVC tomcat

When I use SpringMVC and tomcat to develop the project I often meet garbled problem. In this page I will show you the right way to use them. The most important thing is making the "input" and "output" encoding same.

Use IDEA Mybatis plugin generate mapper files

Mybatis is a light weight Java persistence framework(compared with Hibernate). You have to write a lot of mapper xml files and mapper interfaces. These things are duplicate works, we can generate them by IDEA Mybatis plugin. In this page I will show you how to use this plugin to generate xml mapper file and mapper interface.

Spring boot scheduled tasks example

In this page I will show you how to use scheduling tasks with Spring Boot. As we all known there is no config file in Spring Boot. We use annotations to config scheduling tasks. This example also works well in Spring.

Count the number of output lines in Linux

If the output or a text file is not too long we can know how many lines. But sometimes the output is to long to show them in one screen. At this point you need wc command to count the numbers of output lines. For example there are many log files like following.

Spring MongoTemplate example

MongoTemplate can help you CURD documents in MongoDB easily. In this page I will show you how to use it. I would recommend you to learn Mongo tutorial first, if you are unfamiliar with commends in MongoDB. For quick start I use Spring Boot to test MongoTemplate.