使用Springboot 踩过的坑

1、通用Mapper

导入jar:

<dependency>
    <groupId>tk.mybatis</groupId>
    <artifactId>mapper</artifactId>
    <version>3.5.3</version>
</dependency>

配置通用mapper如下:application.yml

# mybatis 通用 mapper
mapper:
  identity: 'SELECT GUID()'
  before: true
  not-empty: true
  mappers:
    - tk.mybatis.mapper.common.Mapper
    - tk.mybatis.mapper.additional.insert.InsertListMapper

其中的application中:

@SpringBootApplication
@EnableTransactionManagement
@MapperScan(basePackages = "com.xiaowei.sdzs.mapper")
public class XDZSApplication {
...
}

mapper 配置:

@org.apache.ibatis.annotations.Mapper
public interface SendOrderDtoMapper extends Mapper<SendOrderDto>, InsertListMapper<SendOrderDto> {
}

程序没有err,也没有警告,但是跑起来的时候,会出现以下问题:

20Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseSelectProvider.dynamicSQL).  

Cause: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseSelectProvider] with root cause
java.lang.NoSuchMethodException: tk.mybatis.mapper.provider.base.BaseSelectProvider.<init>()

这个问题,当时我也一脸蒙比,后来查询了相关资料,才发现,是使用错Mapper扫描工具了了、下图中的org改为tk即可。tk才是通用mapper的扫描管理工具

展开阅读全文

没有更多推荐了,返回首页