SpringBoot整合tk.mybatis
appleyk 人气:0pom配置如下(标准简易版):
<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即可:
加载全部内容