2019-10-10 20:33:37.408 INFO 6033 --- [ XNIO-1 task-1] c.l.q.w.rest.errors.ExceptionTranslator : Exception in controller encountered
'java.util.NoSuchElementException: No value present'
at java.util.Optional.get(Optional.java:135)
at com.lenovo.quotation.service.QuoteLineService.modifyGuidanceAndContractEndDateAfterChangeCP(QuoteLineService.java:1280)
at com.lenovo.quotation.service.QuoteLineService$$FastClassBySpringCGLIB$$d51f02ce.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)
解决方法
当通过jpa通过id查询时,使用 findById(id).get(),当id对应的主键ID为空时
,会报错如上
当id对应的主键ID为空时,如下
classroom(one)-> student(many)
student表中,classroom_id为空时会导致报错:java.util.NoSuchElementException: No value present
详细讲解
https://blog.csdn.net/fly_as_tadpole/article/details/84786840