Open ITDragonBlog opened 6 years ago
能不能提供完整的异常信息?
你这个是不是因为你的parentId的类型是基本数据类型? 我刚遇到这样的问题,在debug里面发现属性数据类型是基本类型的在proptyMap里面都不存在,修改成其对应的包装类型后就不会报这个错了。 这个应该是一个bug。
后来跟踪的时候(EntityHelper-->EntityResolve->DefaultEntityResolve),发现默认实现里面有对是不是数据是简单类型还是复杂类型有做处理。(具体的还未细看)。
补充,在DefaultEntityResolve中,第74行for循环里(如下所示),基本数据类型会被忽略(这里检查了几个配置与和数据类型,初入这段代码没懂这些配置的作用)
for (EntityField field : fields) {
//如果启用了简单类型,就做简单类型校验,如果不是简单类型,直接跳过
//3.5.0 如果启用了枚举作为简单类型,就不会自动忽略枚举类型
//4.0 如果标记了 Column 或 ColumnType 注解,也不忽略
if (config.isUseSimpleType()
&& !field.isAnnotationPresent(Column.class)
&& !field.isAnnotationPresent(ColumnType.class)
&& !(SimpleTypeUtil.isSimpleType(field.getJavaType())
||
(config.isEnumAsSimpleType() && Enum.class.isAssignableFrom(field.getJavaType())))) {
continue;
}
processField(entityTable, field, config, style);
}
基本类型?贴个代码看看。
基本类型?贴个代码看看。
项目的依赖为:
compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '1.3.2'
compile group: 'tk.mybatis', name: 'mapper-spring-boot-starter', version: '2.1.0'
compile ("com.github.pagehelper:pagehelper-spring-boot-starter:1.2.3"){
exclude group: 'org.mybatis.spring.boot', module: 'mybatis-spring-boot-starter' //by both name and group
}
在混合有基本数据类型时的model(15个属性,4个基本类型):
mapper是这样的:
在service里面是这样的:
然后debug后,example里面的propMap只有11个: 请求结果是:
把那四个基本类型更换为相应的包装类型后,如下所示(这里15个属性都被加载了): 查询结果为: 。
从这里来看基本类型确实在项目启动后就没有被加载到propMap里面,不知道是不是要设置什么?
实体和propertyMap分别是: 请求结果是: 两个以ID结尾的都不可以
版本:mapper-spring-boot-starter:2.0.4 发现一个问题:若实体类中属性名中如果带有id,都会提示:当前实体类不包含名为xxx的属性!