前言

这个项目是springboot 项目使用thymeleaf模板的,主要错误是前端HTML页面使用thymeleaf获取后台传过来的值有问题(获取不到,或者为空null)

错误信息

1、第一个错误:转发的用成了重定向 redirect:/main

2021-11-18 21:02:01.321 ERROR 9272 — [nio-8082-exec-4] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8082-exec-4] Exception processing template “main”: An error happened during template parsing (template: “class path resource [templates/main.html]”)
*
* org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: “class path resource [templates/main.html]”)
* at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
* Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: “page.getCurrent()” (template: “main” - line 86, col 17)
* 这里不能使用重定向:否则前端数据不能通过thymeleaf获取

2、第二个错误:null值错误

org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field ‘records’ cannot be found on null

解决办法

1、第一个错误是我后台查询的数据发往前端HTML页面的时候,没有对应的值,不能使用重定向,否则前端数据不能通过thymeleaf获取。直接去掉 redirect,直接 return “main";
2、第二个错误,和第一个有点相似,这个错误,页面可以找到后台相应的数据,但是没有经过相应的请求,获取不到分页数据。如果直接从登录界面进入这个页面是错误的,因为这里用到了另外一个请求的page分页查询的数据,直接进入是没有查询的,page分页数据为null。所以只能先发送那一个请求查询到page分页数据才能成功的到达main页面。

对应的部分代码

1、前端代码main.html

<!--员工数据表格显示-->
<div class="container table-responsive" style="margin-top: 50px"><table class="table table-bordered"><caption class="caption"><a th:href="@{/showemp}">显示员工信息</a> </caption><thead><tr><th>序号</th><th>ID</th><th>Name</th><th>Password</th><th>操作</th></tr></thead><tbody><tr th:each="book,statu:${page.records}"><th>[[${statu.count}]]</th><td th:text="${book.id}"></td><td>[[${book.name}]]</td><td>[[${book.password}]]</td><td><a th:href="@{/delete}" type="button" class="btn btn-danger btn-sm">delete</a><a th:href="@{/update}" type="button" class="btn btn-info btn-sm">update</a></td></tr></tbody></table>
</div>

2、CrudController.java

@Controller
public class CrudController {@AutowiredBookServiceImpl bookService;@GetMapping("/showemp")public String selectAll(@RequestParam(value = "pn",defaultValue = "1")Integer pn,Model model){Page<Book> page = new Page<>(pn,2);Page<Book> bookPage = bookService.page(page, null);model.addAttribute("page",bookPage);System.out.println(bookPage.getCurrent());System.out.println(bookPage.getRecords().size());/*** 2021-11-18 21:02:01.321 ERROR 9272 --- [nio-8082-exec-4] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8082-exec-4] Exception processing template "main": An error happened during template parsing (template: "class path resource [templates/main.html]")** org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/main.html]")*    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]* Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "page.getCurrent()" (template: "main" - line 86, col 17)* 这里不能使用重定向:否则前端数据不能通过thymeleaf获取*/
//        return "redirect:/main";return "main";}
}

3、LoginController.java

@PostMapping("/login")public String LoginValidation(Book book,RedirectAttributes redirectAttributes){String name = book.getName();String password = book.getPassword();Map<String,Object> map = new HashMap<>();map.put("name",name);map.put("password",password);QueryWrapper<Book> queryWrapper = new QueryWrapper<>();queryWrapper.ge("name",name );queryWrapper.ge("password",password);Book one = bookService.getOne(queryWrapper);if (one.toString()!=null){/*** org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'records' cannot be found on null* 如果直接从登录界面进入这个页面是错误的,因为这里用到了showemp这个请求的page分页查询的数据,直接进入是没有查询的,page分页数据为null* 所以只能先发送showemp请求查询到page分页数据才能成功的到达main页面。*/
//            return "redirect:/main";return "redirect:/showemp";}return "login";}

thymeleaf.TemplateEngineException processing template “main“: An error happened during template pars相关推荐

  1. An error happened during template parsing (template: class path resource [templates/emp/list.html]

    报错信息如下: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing ...

  2. Cannot render error page for request [/list.html] and exception [An error happened during template p

    Cannot render error page for request [/list.html] and exception [An error happened during template p ...

  3. (理解和3种方法完全解决pycharm报错)main.py: error: the following arguments are required: -d/--dataset

    文章目录 背景 理解 完全解决 方法1 方法2 方法3 背景 很多人只说解决方案,却不说原因,遂有此篇. 在pycharm中直接运行如下代码main.py报错: import argparse if ...

  4. iBatis resultMap出错 The error happened while setting a property on the result object 解决办法

    http://blog.csdn.net/itshu/article/details/3402253 错误: org.springframework.jdbc.UncategorizedSQLExce ...

  5. ubuntu中遇到jupyter出现问题ValueError: signal only works in main thread ERROR:tornado.application:Except

    问题:ValueError: signal only works in main thread  ERROR:tornado.application:Except 解决:pip install &qu ...

  6. QtCreator编译错误: -1: error: [debug/main.o] Error 1 问题的解决办法

    在使用Qt的时候经常会出现一些莫名奇妙的编译报错,有时候真的是无语,经常会遇到诸如 -1: error: [debug/main.o] Error 1 这样的问题,调试了很多次后发现和我自己设置的预编 ...

  7. Main.obj : error LNK2019: 无法解析的外部符号 _Direct3DCreate9@4,该符号在函数 long __cdecl InitD3D(struct HWND__ *)

    错误问题: Main.obj : error LNK2019: 无法解析的外部符号 _Direct3DCreate9@4,该符号在函数 "long __cdecl InitD3D(struc ...

  8. An unknown server-side error occurred while processing the command. Original error: Error executing

    Appium报错:An unknown server-side error occurred while processing the command. Original error: Error e ...

  9. snmp4j使用v3连接报异常:Message processing model 3 returned error: Unknown security name

    异常现象 java通过snmp4j使用snmpv3连接偶而会出现异常: org.snmp4j.MessageException: Message processing model 3 returned ...

最新文章

  1. 程序员拯救乐坛?OpenAI用“逆天”GPT2.0搞了个AI音乐生成器
  2. dubbo扫描第三方包_今天来浅谈一下dubbo
  3. Hadoop Yarn容量调度器特点和分配算法介绍
  4. 柯南君:看大数据时代下的IT架构(4)消息队列之RabbitMQ--案例(Helloword起航)...
  5. socket 端口和地址复用
  6. 在本地实现完成多台服务器之间文件拷贝
  7. 阿里可观测性数据引擎的技术实践
  8. 软件开发工程师--经验之谈
  9. 无人车企哪家强?通用第一Waymo第二,苹果特斯拉进黑榜
  10. yarn logs -applicationId 无法导出logs日志 Log aggregation has not completed or is not enabled.
  11. html校园网页设计作品欣赏,26张很棒网页首屏设计作品欣赏
  12. 配置计算机系统doc,计算机的基本配置.doc
  13. 如何提高英文的科研写作能力(转自施一公的博客)
  14. CAD2006 ----VBA(Hello World)
  15. Linux系统下如何解压压缩包内某个文件
  16. 作业——机器学习教你预测商品销售额
  17. 大棚养殖茄子如何“避坑”?资产监控技术提出保障!
  18. VUE3祖孙组件传值调用方法
  19. 数据库开发转行大数据开发工程师怎么样?
  20. 在gitee上部署静态html表白烟花页面,Gitee Go (持续集成)服务(保姆级图文+实现代码)【杂记】

热门文章

  1. ubuntu系统配置记录
  2. 高斯金字塔和拉普拉斯金字塔
  3. HashMap面试底层原理(原作者很厉害)
  4. Nice, 我用AI给表情包分门别类
  5. java项目使用说明_java项目 BeanCopier使用说明
  6. 【弄nèng - Elasticsearch】DSL入门篇(十三)—— Index Template
  7. jieba分词原理 ‖ 词性标注
  8. 三问网约租车,如何辨别真伪共享经济?
  9. Java web集成支付宝电脑支付接口(沙箱环境)
  10. HGE系列之五 管中窥豹(基础类别)