728x90

 

프로젝트 중 신규 페이지와 기능을 추가하고  dto를 추가했는데,

오류 메시지가 나오면서 페이지가 전혀 뜨지 않았다......

 

에러문구

2023-06-01 16:29:30.593 ERROR 4304 --- [nio-9091-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/bus/register.html]")] with root cause org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'BusNo' cannot be found on null at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:219) ~[spring-expression-5.3.27.jar:5.3.27] at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:106) ~[spring-expression-5.3.27.jar:5.3.27] at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:53) ~[spring-expression-5.3.27.jar:5.3.27] at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:412) ~[spring-expression-5.3.27.jar:5.3.27] at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:93) ~[spring-expression-5.3.27.jar:5.3.27] at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:114) ~[spring-expression-5.3.27.jar:5.3.27] at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:338) ~[spring-expression-5.3.27.jar:5.3.27] at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:265) ~[thymeleaf-spring5-3.0.15.RELEASE.jar:3.0.15.RELEASE] at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:166) ~[thymeleaf-3.0.15.RELEASE.jar:3.0.15.RELEASE] at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66) ~[thymeleaf-3.0.15.RELEASE.jar:3.0.15.RELEASE] at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109) ~[thymeleaf-3.0.15.RELEASE.jar:3.0.15.RELEASE] at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138) ~[thymeleaf-3.0.15.RELEASE.jar:3.0.15.RELEASE]

 

빨간 색 내용을 검색해보니,

객체가 null 이어서 조회할 수 없어 생기는 오류라고 한다.

 

간단하게 th:value 에서  dto에 ?를 붙여 해결할 수 있었다.

신규 테이블이라 아예 데이터가 없어서 생긴오류 같다.

 

적용

?만 넣어주니 페이지가 제대로 나왔다 ㅠ_ㅠ

 

 

다른 방법으로는

th:if 문으로 데이터 분기문을 사용할 수 있다고 한다.

 

아래 참고

https://ssd0908.tistory.com/entry/thymeleaf-if-else-%EC%A1%B0%EA%B1%B4%EB%AC%B8-%EC%82%AC%EC%9A%A9%EB%B0%A9%EB%B2%95

728x90

+ Recent posts