You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot程序显示‘post’而非指定数据的问题求助

排查页面仅显示"post"字符串的问题
  • 检查Controller数据传递逻辑

    • 确认PostController返回模板时,是否通过model.addAttribute("post", postInstance)将Post实例存入模型,而非传入字符串"post"。
    • 核对返回的视图名称是否与templates下的post.html完全匹配,避免拼写错误。
  • 检查页面模板表达式正确性

    • 若使用Thymeleaf,确保页面已引入命名空间:<html xmlns:th="http://www.thymeleaf.org">,否则表达式无法被解析,会原样输出字符串。
    • 确认页面中使用的变量表达式正确,比如显示Post标题应写${post.title},而非直接写post(这会直接输出字符串"post")。
  • 检查Post实体类的属性访问权限

    • 确保Post类的所有需要在页面展示的属性(如title、content等)都有公开的getter方法,Thymeleaf依赖getter读取属性值。
    • 核对实体类属性名与页面表达式中的名称一致,比如实体类属性为postContent,页面需对应使用${post.postContent}。
  • 验证Post对象数据有效性

    • 确认Controller中传递的Post对象已正确初始化(如从数据库查询到数据,或手动赋值),避免传递空对象或未赋值的实例。

内容的提问来源于stack exchange,提问作者Ang Theow Meng

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 02:12:37