MyBatis | SELECT Queries | Values That Can Be Specified for resultType

resultType specifies what Java form the query result should be converted into.

In general, specify the FQCN (Fully Qualified Class Name) of the class to convert to, such as java.util.Map.

However, aliases are predefined for some commonly used forms, so they can be specified with short names.

The following list was extracted from org.apache.ibatis.type.TypeAliasRegistry.

Alias Data type
string String
date Date
map Map
hashmap HashMap
list List
arraylist ArrayList
decimal BigDecimal
bigdecimal BigDecimal
biginteger BigInteger
_byte byte
_long long
_short short
_int int
_integer int
_double double
_float float
_boolean boolean
_byte[] byte[]
_long[] long[]
_short[] short[]
_int[] int[]
_integer[] int[]
_double[] double[]
_float[] float[]
_boolean[] boolean[]
byte Byte
long Long
short Short
int Integer
integer Integer
double Double
float Float
boolean Boolean
byte[] Byte[]
long[] Long[]
short[] Short[]
int[] Integer[]
integer[] Integer[]
double[] Double[]
float[] Float[]
boolean[] Boolean[]
object Object
date[] Date[]
decimal[] BigDecimal[]
bigdecimal[] BigDecimal[]
biginteger[] BigInteger[]
object[] Object[]
collection Collection
iterator Iterator
ResultSet ResultSet

For primitive types, add an underscore (_) at the beginning. Be careful, because without the underscore the alias refers to the wrapper class.

Defining aliases

Aliases can be defined freely.

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
  <typeAliases>
    <typeAlias type="foo.bar.Hoge" alias="Hoge" />
  </typeAliases>

  ...
</configuration>
  • You can declare aliases with the <typeAlias> tag in the main configuration file, mybatis-config.xml.

Defining aliases by package

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
  <typeAliases>
    <package name="foo.bar"/>
  </typeAliases>

  ...
</configuration>
  • You can define aliases by package with the <package> tag.
  • In this case, the class name itself becomes the alias.