错误描述:在执行单元测试时,执行到new Example时抛出异常,提示无法获取实体类xxx对应的表名
Example example = new Example(ServeSubscribeRecord.class);Example.Criteria criteria = example.createCriteria();criteria.andEqualTo("serveCode", serveCode);criteria.andEqualTo("thirdUserId", thirdUserId);criteria.andEqualTo("subscribeType", SubscribeTypeEnum.AUTO_SUBSCRIBE);criteria.andEqualTo("subscribeStatus", SubscribeStatusEnum.INIT.getCode());serveSubscribeRecordMapper.updateByExampleSelective(subscribeRecord, example);
解决办法
@Beforepublic void before() {// java.lang.RuntimeException: 无法获取实体类xxx.dao.entity.ServeSubscribeRecord对应的表名!// 该问题原因是由于缺少了spring的启动过程,导致实体类的信息没有添加到容器中导致该异常,在单测中手动添加即可Config config = new Config();// ServeSubscribeRecord为对应实体类EntityHelper.initEntityNameMap(ServeSubscribeRecord.class, config);}
相关的关键代码
Example.java:93
EntityHelper.java:65