首先,提一个思考题:在mapper.xml文件中写sql的时候,parameterType指明入参类型的时候,为什么只需要写String,Long,Integer等,而不用写java.lang.String,java.lang.Long这样呢?
其实是因为springboot在启动并自动初始化bean的过程中,会去加载一个叫TypeAliasRegistry的类,该类的构造器初始化了常用的所有数据类型如下:
private final Map<String, Class<?>> typeAliases = new HashMap();
public TypeAliasRegistry() {
this.registerAlias("string", String.class);
this.registerAlias("byte", Byte.class);
this.registerAlias("long", Long.class);
this.registerAlias("short", Short.class);
this.registerAlias("int", Integer.class);
this.registerAlias("integer", Integer.class);
this.registerAlias("double", Double.class);
this.registerAlias("float", Float.class);
this.registerAlias("boolean", Boolean.class);
this.registerAlias("byte[]", Byte[].class);
this.registerAlias("long[]", Long[].class);
this.registerAlias("short[]", Short[].class);
this.registerAlias("int[]", Integer[].class);
this.registerAlias("integer[]", Integer[].class);
this.registerAlias("double[]", Double[].cla