Java Mybatis懒加载报错末尾显示_$$_jvst12a_0["handler"])的解决方案

异常信息

Type definition error: [simple type, class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactoryEnhancedResultObjectProxyImpl];nestedexceptioniscom.fasterxml.jackson.databind.exc.InvalidDefinitionException:Noserializerfoundforclassorg.apache.ibatis.executor.loader.javassist.JavassistProxyFactoryEnhancedResultObjectProxyImpl]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactoryEnhancedResultObjectProxyImpl];nestedexceptioniscom.fasterxml.jackson.databind.exc.InvalidDefinitionException:Noserializerfoundforclassorg.apache.ibatis.executor.loader.javassist.JavassistProxyFactoryEnhancedResultObjectProxyImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.ruoyi.framework.web.page.TableDataInfo[“rows”]->com.github.pagehelper.Page[0]->com.ruoyi.project.system.student.domain.ZStudent_$$_jvst12a_0[“handler”])

解决方法

  1. 关闭该查询的懒加载 fetchType="eager"
    下面的两种方法我也试过,好像并没有什么作用,在进行序列化的时候就会出现问题比如说BackstageRole会变成Backstage_$$_jvst12a_0这种代理对象(非原始对象)。
    <resultMap id="RoleMap" type="com.hyper.netman.entity.business.BackstageRole">
        <result column="id" property="id"/>
        <result column="role_name" property="roleName"/>
        <result column="role_desc" property="roleDesc"/>
        <result column="create_time" property="createTime"/>
        <result column="modify_time" property="modifyTime"/>
        <!--需要关闭懒加载,不然对象不是原来的对象-->
        <collection property="resources" column="id" javaType="list" fetchType="eager" select="getRolesMenus"/>
    </resultMap>
  1. 返回的类加上注解(即实体类)
@JsonIgnoreProperties(value = { "handler" })
public class BackstageRole{}
  1. 配置json转换器属性 SerializationFeature.FAIL_ON_EMPTY_BEANS为false
spring:
  jackson:
    serialization:
      FAIL_ON_EMPTY_BEANS: false
posted @ 2020-05-27 08:41  itwetouch  阅读(1506)  评论(0编辑  收藏  举报