Property or field ‘XXX‘ cannot be found on null

Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "name" (template: "admin/types-input" - line 32, col 71)
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "name" (template: "admin/types-input" - line 32, col 71)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1021E: A problem occurred whilst attempting to access the property 'name': 'Unable to access property 'name' through getter method'
org.hibernate.LazyInitializationException: could not initialize proxy [com.athome.blog.pojo.Type#15] - no Session
	at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:170) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
	at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:310) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor.intercept(ByteBuddyInterceptor.java:45) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
	at org.hibernate.proxy.ProxyConfiguration$InterceptorDispatcher.intercept(ProxyConfiguration.java:95) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]

已有开发环境如下

Windows平台

jdk1.8、maven已配置

开发工具:Intellij IDEA

在使用springboot 1.XX时,JpaRepository支持findOne(ID)方法

public Type getType(Long id) {
        return typeRepository.findOne(id);
    }
    或者
    public Type getType(Long id) {
        return typeRepository.getOne(id);
    }

但是在springboot 2.XX时findOne()方法不能这样简单使用,于是使用
findById()

public Type getType(Long id) {
        Optional<Type> type = typeRepository.findById(id);
        return type.get();
    }

完美解决

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值