美文网首页
springMVC返回jean错误

springMVC返回jean错误

作者: 轻云绿原 | 来源:发表于2020-07-05 17:46 被阅读0次

    Account

    public class Account implements Serializable {
        private Integer id;
        /**
         * 用户姓名
         */
        private String username;
        /**
         * 余额
         */
        private Float balance;
        /**
         * 用户
         */
        private User user;
    }
    

    User

    public class User implements Serializable {
        private Integer id;
        /**
         * 真实姓名
         */
        private String name;
        /**
         * 头像
         */
        private String avatar;
    }
    

    在springMVC里直接返回Account时错误

    前提

    使用mybatis查询Account时,使用fetchType="lazy"

    错误

    Type definition error: [simple type, class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.ppf.domain.Account_$$_jvst37e_0["handler"])

    解决

    只要在Account类前加JsonIgnoreProperties(value = {"handler"})就行了

    @JsonIgnoreProperties(value = {"handler"})
    public class Account implements Serializable {
        private Integer id;
         ...
    }
    

    相关文章

      网友评论

          本文标题:springMVC返回jean错误

          本文链接:https://www.haomeiwen.com/subject/ajgvqktx.html