项目中使用JUnit & Mocktio进行单元测试,如果代码中使用LambdaQueryWrapper进行条件构造,在DO类中有类似@TableId、@TableLogic等注解,在执行单元测试时会报错 MybatisPlusException: can not find lambda cache for this property [] of entity []
假如一个test类里面使用到的方法多的话,可以使用before注解让这行代码在测试类中所有方法执行之前就添加。在junit 5.x中,@Before主键被@BeforeEach所替代。

 @BeforeEach
    public void initTable() {
        TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), Xxx.class);
    }
 
或者
 @Before
    public void init() {
        TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), Xxx.class);
    }

具体分析参考:

can not find lambda cache for this property [XXX] of entity [com.XXX.XXX]_V六块腹肌的程序员的博客-CSDN博客

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐