Mybatis Dynamic SQL

1. If <select id="findActiveBlogWithTitleLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <if test="title != null"> AND title like #{title} </if> </select> 2. Choose, When, Otherwise <select id="findActiveBlogLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <choose> # choose only one case among many options <when test="title != Read more…

A Template of JUnit5 with Mockito

@ExtendWith(MockitoExtension.class) class ArticleManagerTest { @Mock ArticleDatabase database; @Mock User user; @Spy @InjectMocks private ArticleManager manager; @BeforeEach void setup(){ // some initialization codes } @Test void shouldDoSomething() { // TODO perform some tests with this managers when(database.some(param)).thenReturn(data); Object res = manager.exe(); assertEquals(res, "data"); verify(database).some(param); } } Reading more: Unit tests with Read more…

MySQL Strings Segmentation

SUBSTRING_INDEX(str, delim, count) str: the string to be split. delim: the delimiter. count: the position of the delimiter. A positive number means extract from left to right, a negative number means extract from right to left. For example: SELECT SUBSTRING_INDEX('100-200-300-400', '-', 1); — output: '100' SELECT SUBSTRING_INDEX('100-200-300-400', '-', 2); — Read more…

Gradle Dependency Collision Resolution

Today I met this error when build my project. SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/apps/… fbb0e/logback-classic-1.2.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/apps/… eca4e/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder] I find that this is a dependency collision which Read more…

Nginx Installation

Official website: http://nginx.org/ Click Download. Choose version campatible with your system. In this article, my system is Linux. Nginx is written in C language. So make sure you have C language environment first. yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel Unzip the software package. tar -zxvf nginx-1.10.0.tar.gz Read more…