修复代码生成模块中:因手动删除 ruoyi_sys_menu 历史菜单数据不干净,导致点击“上级菜单”出现500的错误 #225
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
修复代码生成模块中:因上一次手动删除 ruoyi_sys_menu 历史菜单数据,而该表的“上级菜单”配置修改并未同步清空,再次点击“上级菜单”时出现500的错误。
复现步骤:
1)用户第一次选择目标表并生成对应的代码和菜单SQL(配置了 上级菜单 这一项), 并且执行菜单SQL完成
2)用户重启服务后发现菜单位置不符合要求,遂删除自动生成的相关代码和菜单SQL,但此时用户并未删除该表的配置信息(尤其是:)
3)用户选择重新生成代码,当点击“上级菜单”这一步时报错,错误如下:
21:10:36.555 [http-nio-10000-exec-25] ERROR o.t.TemplateEngine - [process,1136] - [THYMELEAF][http-nio-10000-exec-25] Exception processing template "system/menu/tree": An error happened during template parsing (template: "class path resource [templates/system/menu/tree.html]") org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/system/menu/tree.html]") at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) …… at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "menu.menuId" (template: "system/menu/tree" - line 12, col 54) at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) at org.attoparser.MarkupParser.parse(MarkupParser.java:257) at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ... 84 common frames omitted Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "menu.menuId" (template: "system/menu/tree" - line 12, col 54) at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:292) …… at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301) ... 86 common frames omitted Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'menuId' cannot be found on null at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:219) ……org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:265) ... 105 common frames omitted 21:10:36.744 [http-nio-10000-exec-25] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - [log,175] - 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/system/menu/tree.html]")] with root cause org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'menuId' cannot be found on null at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:219) ……
经过分析,发现是点击“上级菜单”时,调用历史设置的菜单ID(2007) 加载后台对应的数据(HTTP接口:system/menu/selectMenuTree/2007 ),而 menuId= 2007 已被手动删除,所以导致SpringEL表达式异常,需要对如下代码做防御性编程:
<input id="treeId" name="treeId" type="hidden" th:value="${menu.menuId}"/> <input id="treeName" name="treeName" type="hidden" th:value="${menu.menuName}"/>