typeAlias通过一个简单的别名来表示一个冗长的类型,这样可以降低复杂度。
表示如下:
<!-- business typeAlias Strart -->
<typeAlias alias="SisUserRole" type="com.xxxxx.sysmgr.model.SisUserRole"/>
<!-- business typeAlias end -->
若不加这句会报如下错误:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'xxxxxxxxxxx' defined in ServletContext resource [/WEB-INF/spring_business.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'SisUserRole'. Cause: java.lang.ClassNotFoundException: Cannot find class: SisUserRole
表示spring找不到该类SisUserRole;
为什么会找不到?
因为在mybatis中的sql写成了省略的部分SisUserRole,是找不到该类的。增加了typeAlias之后就不用写com.xxxxxx.sysmgr.model了。
<insert id="save" parameterType="SisUserRole" keyProperty="id">