MyBatis Snippets

Use List of Parameters in Annotation-based Query Possible using MyBatis Dynamic SQL feature package com.hascode.example.mybatis; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; @Mapper public interface SampleMapper { @Select({"<script>", "SELECT sample.bar", "FROM sampletable sample", "WHERE sample.id IN", "<foreach item='item' index='index' collection='ids'", "open='(' separator=',' close=')'>", "#{item}", "</foreach>", "</script>"}) List<Foo> getSamplesMatchingIds(@Param("ids") List<String> ids); } The mapper may now be used with a list of parameter objects: var samples = sampleMapper.getSamplesMatchingIds(List.of("24059e5b-aa07-424d-855e-50f499b8f697", "65140fc0-fc9f-42d2-9531-5e5d6caeba30")); Call a Procedure package com.hascode.example.mybatis; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Options; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.mapping.StatementType; @Mapper public interface SampleMapper { @Select("CALL SCHEMA.CL.setScope(#{scope})") @Options(statementType = StatementType.CALLABLE) void setScope(int scope); } ...

March 1, 2010 · 1 min · 101 words · Micha Kops

Spring Boot Snippets

Define and Configure Log Groups This allows to configure a group of loggers at the same time Define a log group named myaspect with two packages application.properties logging.group.myaspect=com.hascode.package1,com.hascode.package2 Configure the log group and set all loggers to level TRACE application.properties logging.level.myaspect=TRACE This is also possible as parameter on startup java -Dlogging.level.myaspect=TRACE myapp.jar Use JUnit 5 with Spring Boot Use newer versions of Surefire and Failsafe plugins: <properties> [..] <maven-failsafe-plugin.version>2.22.0</maven-failsafe-plugin.version> <maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version> </properties> ...

March 1, 2010 · 6 min · 1082 words · Micha Kops