SpringBoot2.0整合tk.mybatis异常解决
pom配置如下(标准简易版):
<parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>2.1.4.release</version> </parent> <properties> <java.version>1.8</java.version> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <project.reporting.outputencoding>utf-8</project.reporting.outputencoding> <tk.mybatis.version>1.1.5</tk.mybatis.version> <pagehelper.version>1.2.3</pagehelper.version> </properties> <dependencies> <dependency> <groupid>tk.mybatis</groupid> <artifactid>mapper-spring-boot-starter</artifactid> <version>${tk.mybatis.version}</version> </dependency> <!-- pagehelper --> <dependency> <groupid>com.github.pagehelper</groupid> <artifactid>pagehelper-spring-boot-starter</artifactid> <version>${pagehelper.version}</version> </dependency> </dependencies>
启动报异常如下:
caused by: java.lang.stringindexoutofboundsexception: string index out of range: -1
caused by: java.lang.stringindexoutofboundsexception: string index out of range: -1
at java.lang.abstractstringbuilder.substring(abstractstringbuilder.java:908)
at java.lang.stringbuilder.substring(stringbuilder.java:76)
at tk.mybatis.mapper.mapperhelper.sqlhelper.getallcolumns(sqlhelper.java:247)
at tk.mybatis.mapper.mapperhelper.sqlhelper.exampleselectcolumns(sqlhelper.java:534)
at tk.mybatis.mapper.provider.exampleprovider.selectbyexample(exampleprovider.java:96)
at tk.mybatis.mapper.provider.exampleprovider.selectbyexampleandrowbounds(exampleprovider.java:111)
at sun.reflect.nativemethodaccessorimpl.invoke0(native method)
at sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)
at sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)
at java.lang.reflect.method.invoke(method.java:498)
at tk.mybatis.mapper.mapperhelper.mappertemplate.setsqlsource(mappertemplate.java:246)
... 29 common frames omitted
有说是版本不兼容的问题,有说什么mapperscan注解换成tk的,都不行,找了半天,原来是因为定义的数据实体类中没有定义任何属性造成的:
导致mapper扫描xml的时候,会去找对应的实体类,结果发现一个字段(列)都没有,于是就抛了异常
博主为什么会出现这种情况呢?
我搭框架的时候,会依据产品设计好controller、service和dao层,dao层的entity我只定义,里面的内容由具体的开发者填充,于是乎就出现了,架子搭好了却跑不起来的尴尬局面,解决的办法就是,entity实体类不要空,随便意思下,给个id即可:
到此这篇关于springboot2.0整合tk.mybatis异常的文章就介绍到这了,更多相关springboot整合tk.mybatis内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!