错误描述:在执行单元测试时,执行到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);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
解决办法
@Before
public void before() {
// java.lang.RuntimeException: 无法获取实体类xxx.dao.entity.ServeSubscribeRecord对应的表名!
// 该问题原因是由于缺少了spring的启动过程,导致实体类的信息没有添加到容器中导致该异常,在单测中手动添加即可
Config config = new Config();
// ServeSubscribeRecord为对应实体类
EntityHelper.initEntityNameMap(ServeSubscribeRecord.class, config);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
相关的关键代码
Example.java:93
EntityHelper.java:65
评论记录:
回复评论: